Global access
-
HELP REQD. Trying to move from VB6 to C# (v2003) I made a MDI application which calls up Child forms from the main Menu of the MDI form. The menu Item is disabled when selected and the Child form shows up. It works fine till this point with the following code. mnuMHlagreement is the Name of the menu Item and frmLicence is the Child form. private void mnuMHlagreement_Click(object sender, System.EventArgs e) { showForm(new frmLicence(), mnuMHlagreement); } private void showForm(Form formName, MenuItem menuName) { // Disable Menu Item menuName.Enabled=false; // Set the Parent Form of the Child window. formName.MdiParent = this; // Set Background Colour. formName.BackColor = cFrmBClr; // Display the new form. formName.Show(); } Now I want to enable the menu Item on the parent MDI form when the Child form is closed, which so far I have not been able to do. I am sure almost all of you out there know how it is done. So please let me know too. Also in VB6 we could add Modules where all the Global declarations, etc. were made. In the above example cFrmBClr is a variable which holds the COlor selected at runtime from a ColorDialog on the MDI form. How do I make this a Global variable so that it can be accessed from any form. I THANK YOU IN ANTICIPATION OF YOUR VALUABLE HELP. BIK
-
HELP REQD. Trying to move from VB6 to C# (v2003) I made a MDI application which calls up Child forms from the main Menu of the MDI form. The menu Item is disabled when selected and the Child form shows up. It works fine till this point with the following code. mnuMHlagreement is the Name of the menu Item and frmLicence is the Child form. private void mnuMHlagreement_Click(object sender, System.EventArgs e) { showForm(new frmLicence(), mnuMHlagreement); } private void showForm(Form formName, MenuItem menuName) { // Disable Menu Item menuName.Enabled=false; // Set the Parent Form of the Child window. formName.MdiParent = this; // Set Background Colour. formName.BackColor = cFrmBClr; // Display the new form. formName.Show(); } Now I want to enable the menu Item on the parent MDI form when the Child form is closed, which so far I have not been able to do. I am sure almost all of you out there know how it is done. So please let me know too. Also in VB6 we could add Modules where all the Global declarations, etc. were made. In the above example cFrmBClr is a variable which holds the COlor selected at runtime from a ColorDialog on the MDI form. How do I make this a Global variable so that it can be accessed from any form. I THANK YOU IN ANTICIPATION OF YOUR VALUABLE HELP. BIK
If you want a parent form to do something based on the action of a child, the best way is to set up a delegate, so that a method in the main form gets called by your child form code, without the two being tightly coupled. 'delegate event C# site:msdn.microsoft.com' is the google string to get the info you need here.
us_bik wrote:
How do I make this a Global variable so that it can be accessed from any form.
.NET, wisely, does not allow the hackery of global variables. If you need something to be visible, make it a static property on a class, then you can access it from anywhere with className.PropertyName. Christian Graus - Microsoft MVP - C++