|
Subject:
|
MDI Child Form Problem (not showing)
|
|
Posted By:
|
panuvin
|
Post Date:
|
9/8/2006 6:41:22 PM
|
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.
frmSearch frmSearch = new frmSearch();
frmSearch.MdiParent = this;
frmSearch.Show();
frmSearch.Focus();
What could I possibly be doing wrong!? Thanks in advance.
|
|
Reply By:
|
Ankur_Verma
|
Reply Date:
|
9/9/2006 5:45:37 AM
|
This code should work. Just make sure that IsMdiContainer is set to True for the main form.
Regards Ankur
|
|
Reply By:
|
panuvin
|
Reply Date:
|
9/9/2006 7:51:37 PM
|
I tried putting this statement:
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?
|
|
Reply By:
|
panuvin
|
Reply Date:
|
9/9/2006 10:35:03 PM
|
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?
|
|
Reply By:
|
Ankur_Verma
|
Reply Date:
|
9/10/2006 9:23:14 AM
|
Please verify that you set the IsMdiContainer property of MDI parent (and not MDI child) to true in the propery window.
Its not required to set it in code again if you have already set it to true in the property window.
If you are still feeling lost, post all the code that you have put in the click handler for menu item/button to open the child form. Also post any initialization code that you have put in the child form.
Regards Ankur
|
|
Reply By:
|
panuvin
|
Reply Date:
|
9/10/2006 3:20:50 PM
|
Just to make sure, I posted the isMdiParent property true on both the IDE and in the code at the form_load and the constructor.
The messagebox appears from the second form, which is the really weird part.
Since the solution/project consists of several thousands of lines of code, it might be difficult to cut just those pieces, although I've already pasted what I think would be relevant. But I can try to cut the code even more to present the code, if not the entire project with every piece of code out of the brackets.
Any more ideas on the strangemess of this case?
|
|
Reply By:
|
Ankur_Verma
|
Reply Date:
|
9/11/2006 10:41:04 AM
|
One thing is for sure, it does sound strange!
Nevertheless, there is no reason why this shouldnt work unless some starter code in child form is making it move to a non-visible- -out-of-the-frame area of the main form window or something of that sort.
With that thought I asked you to see if its possible to post the two most relevant pieces of code.
First is all the code that you have written to open the child form in the click event handler of the main form menu item/button and
Second is the initialization code in the child form that 'you have written' if any.
Regards Ankur
|
|
Reply By:
|
panuvin
|
Reply Date:
|
9/11/2006 1:36:38 PM
|
Thanks, this is really weird and I appreciate your continued help!
Here is the code to open the child form:
[code[ frmSearch frmSearch = new frmSearch(); //frmSearch.MdiParent = this; //<-- works without this frmSearch.Show(); frmSearch.Activate(); //frmSearch.Focus(); //<-- don't think i need this b/c of Activate() [/code]
Initiation of Child form: ...I wasn't sure if just the constructor was enough, and since even that included a function, I've copied it onto my ftp
FTP-> http://www.justindevelopment.com/frmSearch.cs
Code Past ->http://rafb.net/paste/results/tuRAke64.html
Please let me know if there's anything you see that shouldn't be there. Thanks again.
Justin/Panuvin
|
|
Reply By:
|
deathout
|
Reply Date:
|
9/13/2006 1:25:58 PM
|
Hi Justin! I had the same problem and think that the reason maybe what is happening to your program:
I was using the ToolStripContainer in my MDI form and it hindered the child form to be shown. Removing the Container and putting the MenuStrip direct in the mdi form solves the problem...
Good Luck 
|