0

Am a new student in C# and am using Microsoft Visual C# 2013.

My aim is to

  1. open a child form inside its MDIparent form
  2. disable the MDIparent form when the child form is active/opened

it was easier in VB.net with

frmStuDetails.ShowDialog()

I have tried

1.

MyChildForm childForm = new MyChildForm();
childForm.ShowDialog(this);

Result....but the problem is that the child form doesn't open within the MDIparent form/container

2. under MDIparent call button

frmViewStuList childForm = new frmViewStuList(this);
childForm.Owner = this;
childForm.Show();

under childForm_Activated

if (this.Owner != null)
{
    this.Owner.Enabled = false;
}

under childForm_Deactivate

if (this.Owner != null)
{
    this.Owner.Enabled = true;
}

Result.....it makes the child form active but freezes the MDIparent when the child form closes

3.

ChildForm child = new ChildForm();
child.Owner = this;
child.Show();

// In ChildForm_Load:

private void ChildForm_Load(object sender, EventArgs e) 
{
  this.Owner.Enabled = false;
}

private void ChildForm_Closed(object sender, EventArgs e) 
{
  this.Owner.Enabled = true;
} 

Result ....It seems to be the best option but the child form doesn't open within the MDIparent

Please help if you have any other idea

Thanks

Nenad
  • 24,809
  • 11
  • 75
  • 93

1 Answers1

0

Disabling MDI parent will disable access to MDI child as well, so it is not feasible approach. And if you are already "faking" MDI child, I would rather open child form as a modal dialog. You can style it and center it, so it feels more as a consistent part of the MDI application.

private void openChildDialogToolStripMenuItem_Click(object sender, EventArgs e)
{
    var childForm = new ChildForm
    {
        ShowInTaskbar = false,
        MinimizeBox = false,
        MaximizeBox = false
    };
    childForm.StartPosition = FormStartPosition.CenterParent;
    childForm.ShowDialog(this);
}
Nenad
  • 24,809
  • 11
  • 75
  • 93