Windows Form과 관련하여 일반 적이 아니지만 전반적으로 C#에서 나아지고 있습니다. 나는 약을위한 프로젝트를 개발 중이다. 음식물. 클래스이고 여러 자식 폼을 허용하는 MDI 폼입니다.MDI 프로젝트에서 자식 폼이 닫힐 때 타이머 이벤트를 중지하는 방법
여기 내 피클입니다. 부모 양식에 타이머가 있습니다. 똑딱 거리면 두 개의 레이블 메서드를 처리하고 텍스트 문서의 문자 수를 계산하고 다른 하나는 확대/축소 수준을 표시합니다.
자식 창이 열릴 때 타이머를 실행할 수 있지만 내 이벤트를 처리 할 수 있지만 창을 닫을 때 타이머를 중지하는 방법을 알아 내려고합니다. 나는 form.closing 이벤트를 시도하고 완료되었을 때 타이머를 사용하지 못하도록 시도했지만 도움이되지 않았습니다.
프로젝트는 텍스트 편집기이고 개체의 이름은 "문서"입니다. 객체가 Disposed 일 때 당연히 예외가 발생하지만이 경우 타이머를 사용하지 않기를 원합니다.
은 ...
void New()
{
// Generate a new form from scratch
TextEditorChild = new Form(); // Declare a variable containing a new Form method
TextEditorChild.Text = "Document " + count.ToString(); // Text Property - also gets the forms order number
TextEditorChild.Icon = Properties.Resources._new_doc_icon; // Use our own icon
TextEditorChild.MdiParent = this; // Ensure we are using the original form as the parent form
Document = new RichTextBox(); // Call a new RichTextBox object
Document.Multiline = true; // Yes, a multiline textbox
Document.Dock = DockStyle.Fill; // Ensure that the textbox fills the new window
TextEditorChild.Controls.Add(Document); // Apply our controls to the child window
TextEditorChild.Show(); // Display the window
count++; // Add this window to a potnetial list of windows, should multiple be opened all at once
timer.Enabled = true;
}
가 여기 내 타이머도 핸들러입니다 .. 다음은 자식 폼의 인스턴스 A를 호출 내 새로운() 메소드의
"삭제 된 개체에 액세스 할 수 없다"
private void timer_Tick(object sender, EventArgs e)
{
charCount.Text = "Characters in the current document: " + Document.TextLength.ToString();
zoom.Text = Document.ZoomFactor.ToString();
}
하나 이상의 TextEditorChild를 열었습니까? – Steve
하나만 있으면 예외가 발생합니다. 실제로 내가 게시 한 코드는 타이머가 시작되도록 허용하지 않습니다. 내 첫 번째 스태 브가 작성되었고 IF 문과 ' if (TextEditorChild == null) { return; } 다른 { // 방법 } ' 이 근무하지만 자식 창을 닫을 때, 나는 다시 메시지를 받았습니다. –