MDI Question
-
Silly question probably, but...Whats the easiest way to communicate from a child Window to a parent window. For example, when the app starts, I want a login form to popup. When entered, that data needs to be available throughout the app. Currently I am using the "OnMdiChildActivate" event on the parent window which works, but it seems as if there should be a better way. Cody C
-
Silly question probably, but...Whats the easiest way to communicate from a child Window to a parent window. For example, when the app starts, I want a login form to popup. When entered, that data needs to be available throughout the app. Currently I am using the "OnMdiChildActivate" event on the parent window which works, but it seems as if there should be a better way. Cody C
You could do this in a couple of ways. If you are in full control of the form that is poping up, you can get the required information by capturing the OnClosing event of the logon form, add the event handler in your MDI parent's load event when you open the mdi child:
//initialise the logon form LogonForm f = new LogonForm(); //Set as child f.MdiParent = this; //Add event handler f.OnClosing += new EventHandler(this.Form1_Closing);
Having done this, write code along these lines to capture properties from the closing logon form:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { LogonForm f = (LogonForm)sender; string Uname = f.Username; string Pword = f.Password; }
obviously you'll need to set up properties such as Username & Password in you logon form that are public. An other way may be to pass up a custom Logon class from the Parent to the child by reference, you can then populate it from the logon form and the information will be available to the parent. Let me know if you'd like me to elaborate on either of these methods.
-
You could do this in a couple of ways. If you are in full control of the form that is poping up, you can get the required information by capturing the OnClosing event of the logon form, add the event handler in your MDI parent's load event when you open the mdi child:
//initialise the logon form LogonForm f = new LogonForm(); //Set as child f.MdiParent = this; //Add event handler f.OnClosing += new EventHandler(this.Form1_Closing);
Having done this, write code along these lines to capture properties from the closing logon form:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { LogonForm f = (LogonForm)sender; string Uname = f.Username; string Pword = f.Password; }
obviously you'll need to set up properties such as Username & Password in you logon form that are public. An other way may be to pass up a custom Logon class from the Parent to the child by reference, you can then populate it from the logon form and the information will be available to the parent. Let me know if you'd like me to elaborate on either of these methods.
Thanks..thats an interesting idea. I actually did it a different way by when the user logs on successfully, having the child window (logon form) populate some public properties of the parent window. I like the idea of having the parent window handle events of the login window however.