Question

I have 1 MDI Form which contains 1 panel control, and 1 Form with 1 button which serves to make panel in MDI not visible.

Code in MDI Form:

    public void displayInit()
    {
        panel1.Visible = false;
    }

Code in Form1:

        private void button1_Click(object sender, EventArgs e)
    {
        displayInit();
    }

The Error is: The name 'displayInit' does not exist in the current context, Any advice please ?

Was it helpful?

Solution

Try referencing the parent (and cast it):

((MyMDIForm)this.MDIParent).displayInit();

This probably isn't the best way to do it though. Consider having the child form raise an event to the MDI parent. Separation of concerns.

OTHER TIPS

The method displayinit() is an instance method, so you need an instance to call it from

MyMDIForm.displayInit();

when constructing the MDI Form keep a reference to it and use that reference when calling it's methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top