Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello codeproject I have an mdi app with menustrip that has two drop down items one of the drop down item links to a form lets say form2.i also have a login form ,i want that whenever a user logs in with a particular role , a button in the form2 should be enabled witout creating a new instance of the form2. But if you click on the form2 menustripitem you should noticed that the button in the form2 haz bin enabled

thanks evryone for your help.
Posted

1 solution

The best way to handle this is via the MDI Parent.

Your login form (assuming it is a MDI Child) should create an event, which the parent handles: LoginStatusChanged for example.
The parent then reads the login information from the login form via one or more public properties and passes it as necessary to the other MDI children, again via public properties.

Each individual child then looks at the new status when the property changes and sets it's menus, tool bars, and other controls to the appropriate state.

The advantage of this approach is that no form needs to know about the existence of the others (except the parent, but since it creates the children, that's allowed)

If you don't know how to do any particular part of this, just ask!
 
Share this answer
 
Comments
Ese ochuko 2-Sep-12 9:26am    
Thank u vry much for your reply but can u please can you show me sme example with codes thanks very much for your response
OriginalGriff 2-Sep-12 10:15am    
For which bit? :laugh:
Remember I have no idea of your skill level, but also I don't want to patronise you or do extra, unnecessary work myself!
Ese ochuko 3-Sep-12 2:29am    
Am a beginner ,i think i need every bit, laugh. Even if u wana add screen shot thats okay by me .thanks very much
OriginalGriff 3-Sep-12 3:17am    
Adding an event is easy: the complete code is at the top of this tip: http://www.codeproject.com/Tips/400287/A-simple-code-snippet-to-add-an-event
(The rest of the tip just makes it easier to add them in VS). To signal the event to the parent, the child form just calls the OnXxxxx routine (OnFilterChange in the example).

Properties are also easy:
public MyProperty { get; set; }
is a complete automatic property, but you can put what code you like in the getter and setter:
public MyOtherProperty
{
get { return myTextBoxWithUserName.Text; }
set
{
myTextBoxWithUserName.Text = value;
if (value == "Not a valid user name")
{
MessageBox.Show("Then why are you setting it?");
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900