주 폼 위에 표시하고 닫은 다음 즉시 MessageBox.Show()
을 사용하여 대화 상자를 표시하는 Windows 양식 응용 프로그램에 양식이 있습니다. 그러나 첫 번째 양식은 여전히 메시지 상자가 표시 될 때 표시되며 메시지 상자에서 확인을 클릭 할 때까지 사라지지 않습니다. 양식의 VisibleChanged
이벤트에 대한 이벤트 처리기에서 메시지 상자를 표시하고 양식과 기본 양식 모두에 Refresh()
을 호출하기 위해 대기 중입니다. 메시지 상자를 표시하기 전에 첫 번째 양식이 완전히 사라 졌는지 확인할 수있는 방법이 있습니까?Windows Form을 "완전히"닫으려면 어떻게해야합니까?
편집 :
다음은 양식이 어떻게 표시되는지 보여주는 코드입니다. 폼은 폐쇄 완료되면
static class Program
{
// The main form is shown like this:
static void Main()
{
Application.Run(new MainForm());
}
}
public class Class1
{
// _modalForm is the first form that is displayed that won't fully go away
// when it is closed.
ModalForm _modalForm;
BackgroundWorker _worker;
public Class1()
{
_modalForm = new ModalForm();
_worker = new BackGroundWorker();
_worker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted
}
public void Method1()
{
_worker.RunWorkerAsync();
// The first form is shown.
_modalForm.ShowDialog();
}
// This code runs in the UI thread.
void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
_modalForm.VisibleChanged += new EventHandler(_modalForm_visibleChanged);
_modalForm.Close();
}
void _modalForm_visibleChanged(object sender, EventArgs e)
{
// When the message box is shown, the other form is still visible
// and remains so until I click OK.
MessageBox.Show("The other form was just closed.");
// Note: I originally tried to use the FormClosed event instead of
// VisibleChanged. Then I tried Deactivate, in attempt to use an event
// that occurred later thinking that might do the trick. VisibleChanged
// is the latest event that I found.
//
}
답변은 기본 양식을 어떻게 표시하는지에 달려 있다고 생각합니다. 마음에 들지 않는 행동을 보여주는 최소한의 코드를 게시 할 수 있습니까? – Karmastan