Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 8th, 2006, 06:41 PM
Authorized User
 
Join Date: Sep 2005
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default MDI Child Form Problem (not showing)

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.

Reply With Quote
  #2 (permalink)  
Old September 9th, 2006, 05:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

This code should work. Just make sure that
IsMdiContainer is set to True for the main form.

Regards
Ankur
Reply With Quote
  #3 (permalink)  
Old September 9th, 2006, 07:51 PM
Authorized User
 
Join Date: Sep 2005
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

Reply With Quote
  #4 (permalink)  
Old September 9th, 2006, 10:35 PM
Authorized User
 
Join Date: Sep 2005
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 With Quote
  #5 (permalink)  
Old September 10th, 2006, 09:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

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 With Quote
  #6 (permalink)  
Old September 10th, 2006, 03:20 PM
Authorized User
 
Join Date: Sep 2005
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 With Quote
  #7 (permalink)  
Old September 11th, 2006, 10:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

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 With Quote
  #8 (permalink)  
Old September 11th, 2006, 01:36 PM
Authorized User
 
Join Date: Sep 2005
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 With Quote
  #9 (permalink)  
Old September 13th, 2006, 01:25 PM
Registered User
 
Join Date: Sep 2006
Location: Teresopolis, RJ, Brazil.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to deathout
Default

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 :)

Reply With Quote
  #10 (permalink)  
Old March 22nd, 2013, 12:49 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default reponse

deatout is rigth. to display your mdi child form, you shouldnt have (*)containers in your mdi parent form. (*) means all controler finish by containers as stripContenair
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying MDI Child Form Menus with MDI Parent ashu_from_india Pro VB 6 3 June 10th, 2008 11:01 PM
Controlling MDI child form from MDI parent panel LuxCoder VB.NET 2002/2003 Basics 7 April 11th, 2007 02:38 PM
Controlling MDI child form from MDI parent panel LuxCoder VB How-To 1 April 9th, 2007 03:25 PM
strange problem while displaying child form in mdi avats General .NET 1 June 20th, 2005 08:06 PM
MDI Child form problem MarkJ Pro VB 6 0 November 17th, 2003 06:07 AM



All times are GMT -4. The time now is 06:12 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.