Jump to content
  • Advertisement
Sign in to follow this  
Ekim_Gram

Unity [.net] MDI troubles - Can't set child to the main form (C#)

This topic is 4679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my Other topic I say how I've begun work on a level editor for the game Breakout with C#. I have the one main form (frmEditor) which has a menu and acts as a parent window for the MDI. File->New brings up another small window that takes a few values to start set up of the level (frmInitLevel). Once the users clicks the OK button on that new initializer form, I have a 3rd form created. This form is the level itself and I would like it to become the child window of the main form. I have the following code in the frmInitLevel OK button click event:
		private void btnOK_Click(object sender, System.EventArgs e)
		{
			frmLevel NewLevel = new frmLevel();
			NewLevel.MdiParent = LevelEditor.Editor;
			NewLevel.Show();
			this.Dispose();
		}
Now the problem is that I can't really access Editor from the LevelEditor class since the Editor form is being used as the main form in the Application.Run() procedure: LevelEditor.cs
using System;
using System.Windows.Forms;

namespace Breakout_Level_Editor
{
	public class LevelEditor
	{
		public static frmEditor Editor = new frmEditor();

		[STAThread]
		static void Main() 
		{
			Application.Run(new frmEditor());
		}
	}
}

Since there is no named declaration of the frmEditor used Application.Run(), I'm unable to set a child window from another class. I was thinking of trying to use static bools or something of the sort but when you start coding like that, things get to be such a mess. Images:
the main form (frmEditor) Image Hosted by ImageShack.us frmInitForm Image Hosted by ImageShack.us frmLevel Image Hosted by ImageShack.us [Edited by - Ekim_Gram on December 18, 2005 10:44:12 PM]

Share this post


Link to post
Share on other sites
Advertisement
If I'm understanding you correctly, why don't you just pass the frmEditor's this reference to the frmInitForm when creating the frmInitForm?

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
If I'm understanding you correctly, why don't you just pass the frmEditor's this reference to the frmInitForm when creating the frmInitForm?


Could you supply some example syntax for me?

Share this post


Link to post
Share on other sites
Your frmInitForm constructor probably looks like this:

public frmInitForm() {
InitializeComponent();
}

Change that to:

public frmInitForm(frmEditor editor) {
InitializeComponent();
editor_ = editor;
}

Add a frmEditor variable called editor_ to the frmInitForm, and when you construct the frmInitForm, pass this to the constructor.

Edit: Alternately you can make your frmInitForm's OK button have a DialogResult value of DialogResult.OK (and give the Cancel button a DialogResult of DialogResult.Cancel) and have the frmEditor check the return value of the ShowDialog() and initialize the frmLevel form itself.

Share this post


Link to post
Share on other sites
Thank you very much, again. I can't believe I wasn't able to think of it like that.

I guess that's what happens when you only code once a week (which also explains the lateness of this post) :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!