S
SagaV9
Guest
First - I think I spent more time locating this forum than I did asking my question. I used to log in into the MSDN site and "Community" was front and center, now I could not get to this forum from MSDN or the main MS site.
Anyways... now that I've vented. I am using Visual Studio 2015, C# and Windows 10, latest update. I have an MDI application with child forms. When I call a child form I do a test in Form Load and if the test fails, I close the form. Knowing that I can't directly close the form in Form_Load, I set a success flag to false and then I close the form in the Shown event.
This works, but the child form briefly flashes before it is closed. I understand that the form must be "painted" before the Shown event.
I did some research and found lots of possible fixes, including using the BeginInvoke form method and overriding methods such as CreateHandle.
Which method is recommended to close the form without it briefly flashing on the screen?
I am using the following code to call the child form:
if (fChildForm == null)
{
fChildForm = new frmChildForm(PerID);
fChildForm.MdiParent = this;
fChildForm.FormClosed += new FormClosedEventHandler(fChildForm_FormClosed);
fChildForm.Show();
}
else
fChildForm.Activate();
The Form Load event uses the person's ID (PerID) to see if it is valid, setting a bool test variable. This bool variable, in turn, sets a bool flag that determines whether the form should proceed or whether it should be closed:
//Variable test is previously set elsewhere in Form_Load event.
if (!test)
{
//Person id not found, display message.
MessageBox.Show("Person id specified not found.",
"Person data",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
//Exit form.
bOK = false;
}
//And the Shown event:
private void fChildForm_Shown(object sender, EventArgs e)
{
if (!bOK)
this.Close();
}
Thanks! Saga
You can't take the sky from me
Continue reading...
Anyways... now that I've vented. I am using Visual Studio 2015, C# and Windows 10, latest update. I have an MDI application with child forms. When I call a child form I do a test in Form Load and if the test fails, I close the form. Knowing that I can't directly close the form in Form_Load, I set a success flag to false and then I close the form in the Shown event.
This works, but the child form briefly flashes before it is closed. I understand that the form must be "painted" before the Shown event.
I did some research and found lots of possible fixes, including using the BeginInvoke form method and overriding methods such as CreateHandle.
Which method is recommended to close the form without it briefly flashing on the screen?
I am using the following code to call the child form:
if (fChildForm == null)
{
fChildForm = new frmChildForm(PerID);
fChildForm.MdiParent = this;
fChildForm.FormClosed += new FormClosedEventHandler(fChildForm_FormClosed);
fChildForm.Show();
}
else
fChildForm.Activate();
The Form Load event uses the person's ID (PerID) to see if it is valid, setting a bool test variable. This bool variable, in turn, sets a bool flag that determines whether the form should proceed or whether it should be closed:
//Variable test is previously set elsewhere in Form_Load event.
if (!test)
{
//Person id not found, display message.
MessageBox.Show("Person id specified not found.",
"Person data",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
//Exit form.
bOK = false;
}
//And the Shown event:
private void fChildForm_Shown(object sender, EventArgs e)
{
if (!bOK)
this.Close();
}
Thanks! Saga
You can't take the sky from me
Continue reading...