Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MDI Child Form Problem (not showing)

Status
Not open for further replies.

panuvin

Programmer
Mar 24, 2004
11
US
I am having difficulty with a MDI child/parent relationship for my C# winforms project. I currently have a several controls (button, menu strip, etc.) that call the same function to open a new child form.

The main form has the propery of MDI container as it was set on the properties window (not programmatically).

However, when I click on the button, the form does not show up. If I make the form so it is not an MDI child (by commenting the second line of code below), it does pop up just fine...but that's not what I want.

Here is the code that I have for the function. I have just recently added the .focus method because I saw that mentioned on another forum post and it didn't work.

Code:
frmSearch frmSearch = new frmSearch();
frmSearch.MdiParent = this;
frmSearch.Show();
frmSearch.Focus();

What could I possibly be doing wrong!? Thanks in advance.
 
Hello,

The MDI form should ha 'IsMdiContainer' property set to TRUE. This code to work must be written in the mdi form's class. Else you will have problems with the keyword 'this'.
Make sure that the code is called be a button that IS defined in the mdi class form.
 
You could simply use: myForm.ShowDialog(this);
Doing so will also put the focus on the main/parent form.
 
The .ShouwDialog() with make that form topmost and wont let change focus, unless it 'posts' a dialog result. This is different than specifying who's the parent. If you use the .MdiParent and the .ShouDialog() then the parent form will host the child and only this will have the focus.
 
I tried putting this statement:

Code:
this.sMdiContainer = true;

into both the constructor and the form_load event without any success. Is there something wrong with the statement itself, or did I put it in the wrong place?

Any other ideas?
 
I have just added a messagebox on the child form and the messagebox does appear, but the child form does not show. So the form must load, but neither the .Activate() or .Show() methods make the form display correctly. Any other ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top