DialogForm within the Boundries

Vivek Dahiya 65 Reputation points

Good Morning , i have a PanelForm . it has two panels topPanel and bottomPanel . One is docked Top and other is docked bottom inside the PanelForm .

public partial class PanelForm : Form
        private Panel topPanel;
        private Panel bottomPanel;

    public PanelForm()

    private void PanelForm_Load(object sender, EventArgs e)
        Form2 form2 = new Form2();
        form2.TopLevel = false;
        form2.FormBorderStyle = FormBorderStyle.None;
        form2.Parent = topPanel;
        form2.Dock = DockStyle.Fill;

when the form loads , it opens a new form named form2 inside PanelForm . Form2 has a button which opens a messagebox on click event .

 private void button1_Click(object sender, EventArgs e)
            MessageBox.Show("This is a message box inside PanelForm.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);


I have been assigned a pretty tough task in which i had to make sure that

the messagebox always open inside the toppanel only so that the user cannot interact with the other controls in the top panel as long as this messagebox is opened but the more ugly part is

even when the messagebox remained open , the user can interact with the panel which is bottom panel .

Now , i am new in c# and windows forms and have spend many hours just to find out , but no success so far . So i request someone here to please suggest a working strategy with an example if possible . One more thing this messagebox is just for showing a dialog form type problem . in actual there would be a form which would be opened as a show dialog .

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,865 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,520 questions
{count} votes

Accepted answer
  1. KOZ6.0 6,210 Reputation points

    When a dialog is displayed modally, the original specification is that windows belonging to that thread become inoperable.

    If it works, it may be a problem with Visual Studio. Please start the exe directly and check the operation

1 additional answer

Sort by: Most helpful
  1. Viorel 114K Reputation points

    Try to create a User Control instead of Form2. Add the button1 and the message box.

    Adjust the main form:

     private void PanelForm_Load(object sender, EventArgs e)
       var uc = new MyUserControl1( );
       topPanel.Controls.Add( uc );
    1 person found this answer helpful.