Hi, i am here to ask some button control problem in Visual studio:

private void button1_Click(object sender, EventArgs e)
        {           
            Report newMDIChild = new Report();
            // Set the parent form of the child window.
            newMDIChild.MdiParent = this;
            // Display the new form.
            newMDIChild.Show();
        }

In my program, when i clicks the button1, it should flow to other interface/window ( Report)from current window (Form1) . However, by my codes above, when i clicks the button, the interface of Report is stack on the interface Form1 and not totally go to that window. What is mistake in my coding?

This example requires that the code in the example is called from a form that has its IsMdiContainer property set to true.
That means that your MainForm has the property IsMdiContainer set to true;

//before creating a new instance of a Report class, do:
this.IsMdiContainer = true;
Report newMDIChile = new Report();
//and the rest of the code

Ya, i already set in properties there, but still has the problem there.. Or is me using wrong code?

I don't know if this helps but it closes the current form containing the button that you click and opens the report when the button is clicked.

// declare this after the class constructor
Report newMDIChild = new Report(); 
  
private void button1_Click(object sender, EventArgs e)
{         
// Hides the current form        
this.Hide();            
// Display the new form.            
newMDIChild.Show();
}

Its work, Thank you very much.

Hi, i am here to ask some button control problem in Visual studio:

private void button1_Click(object sender, EventArgs e)
        {           
            Report newMDIChild = new Report();
            // Set the parent form of the child window.
            newMDIChild.MdiParent = this;
            // Display the new form.
            newMDIChild.Show();
        }

In my program, when i clicks the button1, it should flow to other interface/window ( Report)from current window (Form1) . However, by my codes above, when i clicks the button, the interface of Report is stack on the interface Form1 and not totally go to that window. What is mistake in my coding?

You may want to employ threading in this case. If you need to perform any type of updates to either window (update main window from child or vice-versa), you will need to make thread-safe calls. This is another learning paradigm in writing Windows Forms applications. I came from a C environment where everything was character-based and this was a whole branch of learning that I had to master. Once you learn the basics it is simple and straight-forward.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.