HaLo2FrEeEk Posted March 24, 2009 Share Posted March 24, 2009 I've tried this for the last hour. I've googled everything I can and nothing I do seems to work. I have a form, the form that you start with, which has a menu strip in it. I put an "about" button on the menu strip with an onclick event that is supposed to open another, smaller, window with information. This smaller window is supposed to be the larger window's child, so I shouldn't be able to select the larger window when the small one is open, and the smaller window should open up inside the larger one. I have tried everything I can think of to make this work, and the smaller window just will NOT do what I say. Either I get an error before runtime, or there is no error and it just doesn't work, or there's no error before but I get an error after runtime! It's driving me crazy. Please if someone could help me, I'd be very thankful! Quote Link to comment https://forums.phpfreaks.com/topic/150834-c-setting-a-form-as-a-child-to-another-form/ Share on other sites More sharing options...
captbeagle Posted July 24, 2009 Share Posted July 24, 2009 By your description, I wasn't sure if you were trying to have the child "About" window show inside the parent form (as in an MDI model) or if you wanted it to be a separate window that merely disabled the parent while in use, so I've gone ahead and created both project demos for you. I assumed you're using Visual Studio of some sort, so these should open. I've also compiled each already at ./bin/Release (and you'd run the .exe file within). Here's a link to download my samples at: http://www.savefile.com/files/2162576 I'll explain the main bits of the code. In the MDI_Child_Sample, within Form1.cs, you needed to set the value for "Is MDI Container" to true for it to work. From there all you should care about is the code: private void aboutToolStripMenuItem_Click( object sender, EventArgs e ) { //Create new instance of the MDI child template form Form About = new Form(); //Set parent for the child window About.MdiParent = this; //Display the child window About.Show(); } It's pretty self-explanatory with the comments and fairly simple to implement. Here's the page I took the comments from (far clearer than what I came up with myself): http://www.codeproject.com/KB/cs/mdiformstutorial.aspx. You can find all sorts of information on that page as to different ways to make your child window display and act. As for the other sample, it just creates a new form and uses a while statement. While the new form is visible, the parent form is not enabled. Thus, when you close the new form, it's not longer visible and you can interact with the parent once again. private void aboutToolStripMenuItem_Click( object sender, EventArgs e ) { Form ChildWindow = new Form(); ChildWindow.ShowDialog(); while (ChildWindow.Visible == true) this.Enabled = false; } Hopefully that answers what you were looking for! Quote Link to comment https://forums.phpfreaks.com/topic/150834-c-setting-a-form-as-a-child-to-another-form/#findComment-882286 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.