How to Close() the MDIChild -during its Form_Load()

Paraman

Member
Joined
Oct 19, 2024
Messages
13
Programming Experience
10+
Hi, I wish to close the MDI-Child Form during its Form_load(). Is it possible?

My Codes

C#:
private void Form_BooksMaster_Load(object sender, EventArgs e)
{
    if (MyDBConnector == false) {
        this.Parent = null;
        //this.Close();  ?? Error : Value Close() cannot be called while doing CreateHandle()
        //this.BeginInvoke(new MethodInvoker(this.Close)); ?? Error C3867 'System.Windows.Forms.Form.Close': non-standard syntax; use '&' to create a pointer to member
        return;   
    }
}
Thanks Again !
 
Solution
Anyway, your easiest option is simply to use the Shown event instead of the Load. Most of the tutorials show using the Load event because that is what people from the VB world are most familiar with and at the time Microsoft was trying to ensure that it would grab the mindshare of VB programmers to move to VB.NET instead of them going looking for other languages/frameworks.

But the true way to fix this is to not even create the form if your database connection is available. Why create and try to show the form and only to turn around and abort showing it? Don't even try to show it.
The second error you are showing is not a normal C# error. Are you translating C++/CLI to C# again?
 
Anyway, your easiest option is simply to use the Shown event instead of the Load. Most of the tutorials show using the Load event because that is what people from the VB world are most familiar with and at the time Microsoft was trying to ensure that it would grab the mindshare of VB programmers to move to VB.NET instead of them going looking for other languages/frameworks.

But the true way to fix this is to not even create the form if your database connection is available. Why create and try to show the form and only to turn around and abort showing it? Don't even try to show it.
 
Solution
Back
Top Bottom