Do events?? (C# Newbi)
-
I have a MdiParent and Child. After the child is called using the .Show, the Parent continues to run code. In VB6, I typically got around this by using do while, or do events. (Hate to admit it, but I just tried until something worked) I am wanting to set this up correctly, so can anyone point me in the right direction on how to hold the parent while the child does its thing. -Thanks in Advance
-
I have a MdiParent and Child. After the child is called using the .Show, the Parent continues to run code. In VB6, I typically got around this by using do while, or do events. (Hate to admit it, but I just tried until something worked) I am wanting to set this up correctly, so can anyone point me in the right direction on how to hold the parent while the child does its thing. -Thanks in Advance
Dwayner79 wrote: have a MdiParent and Child. After the child is called using the .Show, the Parent continues to run code. Uhhh... That's the way it's supposed to work! Are you talking about running a form as a dialog instead of a form? In that case, use
.ShowDialog()
, not.Show()
. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome -
Dwayner79 wrote: have a MdiParent and Child. After the child is called using the .Show, the Parent continues to run code. Uhhh... That's the way it's supposed to work! Are you talking about running a form as a dialog instead of a form? In that case, use
.ShowDialog()
, not.Show()
. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming GnomeI understand the difference, I do not want to stop everything in the Parent, I want to pause the code... Here is some more clarity... If I comment out the call to the child form, the parent forms loads and sits there. This seems correct. If I call the Child, and set a breakpoint, and F11 through the code, everything works fine. The child is called, and the code in the child loads fine. If I Run the code without the breakpoint, the following error occures: "An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object reference not set to an instance of an object." My thoughts on this is that the code is failing because the parent is leaving the function that called the child. The question is should I showdialog and lose the ability to use the parent window functions, Should I do a do While type statement, or is there another way to handle this kind of situation? Thanks for the advice. Edit: You cannot run a showdialog on a child form. So there has to be something that can "pause" the Parent.
-
I understand the difference, I do not want to stop everything in the Parent, I want to pause the code... Here is some more clarity... If I comment out the call to the child form, the parent forms loads and sits there. This seems correct. If I call the Child, and set a breakpoint, and F11 through the code, everything works fine. The child is called, and the code in the child loads fine. If I Run the code without the breakpoint, the following error occures: "An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object reference not set to an instance of an object." My thoughts on this is that the code is failing because the parent is leaving the function that called the child. The question is should I showdialog and lose the ability to use the parent window functions, Should I do a do While type statement, or is there another way to handle this kind of situation? Thanks for the advice. Edit: You cannot run a showdialog on a child form. So there has to be something that can "pause" the Parent.
-
private void MainParent_Load(object sender, System.EventArgs e) { LoadNewConfig(); } private void LoadNewConfig() { ControllerForm controllerForm = new ControllerForm(); controllerForm.MdiParent = this; controllerForm.Show(); } There is nothing to this code. The three lines in LoadNewConfig are the ones I remove and it works fine. I Turned on the Exception Break into debugger option. (CTRL-ALT-E) and now I cac't get it to happen again. grrrrrr
-
private void MainParent_Load(object sender, System.EventArgs e) { LoadNewConfig(); } private void LoadNewConfig() { ControllerForm controllerForm = new ControllerForm(); controllerForm.MdiParent = this; controllerForm.Show(); } There is nothing to this code. The three lines in LoadNewConfig are the ones I remove and it works fine. I Turned on the Exception Break into debugger option. (CTRL-ALT-E) and now I cac't get it to happen again. grrrrrr
-
I understand the difference, I do not want to stop everything in the Parent, I want to pause the code... Here is some more clarity... If I comment out the call to the child form, the parent forms loads and sits there. This seems correct. If I call the Child, and set a breakpoint, and F11 through the code, everything works fine. The child is called, and the code in the child loads fine. If I Run the code without the breakpoint, the following error occures: "An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object reference not set to an instance of an object." My thoughts on this is that the code is failing because the parent is leaving the function that called the child. The question is should I showdialog and lose the ability to use the parent window functions, Should I do a do While type statement, or is there another way to handle this kind of situation? Thanks for the advice. Edit: You cannot run a showdialog on a child form. So there has to be something that can "pause" the Parent.
Dwayner79 wrote: My thoughts on this is that the code is failing because the parent is leaving the function that called the child. Of course it is! That's what it's supposed to do. The problem is not because the function is returning, but because your code, somewhere else down the line, of either the MDI Parent or the Child form, is referencing an object that doesn't have an instance yet. If you're running this under the debugger, it'll show you which line is throwing the exception. What does the code look like? I'd be willing to bet that it has something to do with the Load event of the Child form. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Does ur ControllerForm have any code yet? If so, can u please post all ControllerForm code that gets called when instantiating? If ur overriding any methods that might be getting called then please post them too.
no overrides... here is the code: I included all the code from the Windows IDE generated. public class ControllerForm : System.Windows.Forms.Form { private DevComponents.DotNetBar.DotNetBarManager dotNetBarManager1; private DevComponents.DotNetBar.DockSite barLeftDockSite; private DevComponents.DotNetBar.DockSite barRightDockSite; private DevComponents.DotNetBar.DockSite barTopDockSite; private DevComponents.DotNetBar.DockSite barBottomDockSite; private System.ComponentModel.IContainer components; string controllerName = ""; private System.Windows.Forms.OpenFileDialog openFile1; string fileName = ""; public ControllerForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } public string ControllerName { get { return controllerName; } set { controllerName = value; } } public string FileName { get { return fileName; } set { fileName = value; } } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.dotNetBarManager1 = new DevComponents.DotNetBar.DotNetBarManager(this.components); this.barBottomDockSite = new DevComponents.DotNetBar.DockSite(); this.barLeftDockSite = new DevComponents.DotNetBar.DockSite(); this.barRightDockSite = new DevComponents.DotNetBar.DockSite(); this.barTopDockSite = new DevComponents.DotNetBar.DockSite(); this.openFile1 = new System.Windows.Forms.OpenFileDialog(); this.SuspendLayout(); // // dotNetBarManager1 // this.dotNetBarManager1.AutoDispatchShortcuts.Add(DevComponents.DotNetBar.eShortcut.F1); this.dotNetBarManager1.AutoDispatchShortcuts.Add(DevComponents.DotNetBar.eShortcut.CtrlC); this.dotNetBarManager1.AutoDispatchShortcuts.Add(DevComponents.DotNetBar.eShortcut.CtrlA); this.dotNetBarManager1.AutoDispatchShortcuts.Add(DevComponents.Do
-
Dwayner79 wrote: My thoughts on this is that the code is failing because the parent is leaving the function that called the child. Of course it is! That's what it's supposed to do. The problem is not because the function is returning, but because your code, somewhere else down the line, of either the MDI Parent or the Child form, is referencing an object that doesn't have an instance yet. If you're running this under the debugger, it'll show you which line is throwing the exception. What does the code look like? I'd be willing to bet that it has something to do with the Load event of the Child form. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
I posted code above. I tried running under the debugger and step through the code, it does not fail. I changed to "Break into the debugger" under the Exceptions window, but it still does not tell me what line of code the problem is on. Thanks for the help.
-
no overrides... here is the code: I included all the code from the Windows IDE generated. public class ControllerForm : System.Windows.Forms.Form { private DevComponents.DotNetBar.DotNetBarManager dotNetBarManager1; private DevComponents.DotNetBar.DockSite barLeftDockSite; private DevComponents.DotNetBar.DockSite barRightDockSite; private DevComponents.DotNetBar.DockSite barTopDockSite; private DevComponents.DotNetBar.DockSite barBottomDockSite; private System.ComponentModel.IContainer components; string controllerName = ""; private System.Windows.Forms.OpenFileDialog openFile1; string fileName = ""; public ControllerForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } public string ControllerName { get { return controllerName; } set { controllerName = value; } } public string FileName { get { return fileName; } set { fileName = value; } } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.dotNetBarManager1 = new DevComponents.DotNetBar.DotNetBarManager(this.components); this.barBottomDockSite = new DevComponents.DotNetBar.DockSite(); this.barLeftDockSite = new DevComponents.DotNetBar.DockSite(); this.barRightDockSite = new DevComponents.DotNetBar.DockSite(); this.barTopDockSite = new DevComponents.DotNetBar.DockSite(); this.openFile1 = new System.Windows.Forms.OpenFileDialog(); this.SuspendLayout(); // // dotNetBarManager1 // this.dotNetBarManager1.AutoDispatchShortcuts.Add(DevComponents.DotNetBar.eShortcut.F1); this.dotNetBarManager1.AutoDispatchShortcuts.Add(DevComponents.DotNetBar.eShortcut.CtrlC); this.dotNetBarManager1.AutoDispatchShortcuts.Add(DevComponents.DotNetBar.eShortcut.CtrlA); this.dotNetBarManager1.AutoDispatchShortcuts.Add(DevComponents.Do
I've run ur code and it works perfectly under these conditions: 1) No devcomponents Could be some fault in the assembly? Have u tried running the code commenting out all DevComponent references? One thing i've noticed in your ContainerLoadControl event handler: Ur safe casting "sender" into a "BaseItem" through "BaseItem item = sender as BaseItem;" but then, on the next line, ur not taking into account that the cast might fail and "item" be a null reference. In that case "item.Name" will fail. Can ur error be in ur event handler? This error might be triggering while the form is performing native calls during loadup and thus the debugger cannot catch it properly. Try commenting it out and see what happens or try putting ur code after the safecast in this way and see what happens: if(item!=null) {//your code}
-
I am a newbie as well, but could you use thread.join to have your parent form wait until the child is complete? Can't remember if each for is it's own thread, or if you would need to start the child form on it's own thread. I think the former is correct. www.lovethosetrains.com