Enabling a tool bar Via MDI Child

I have a situation where I want to use a login screen for determining which toolbar to load on my MDI parent application. But, I can't seem to make it work.

I first load the MDI parent and then Load a Child form for the login page. Once the person logs in I can't enable the toolbar on the MDI parent from the child. Can anyone please point me in the right direction.

[372 byte] By [codefund.com] at [2007-12-16]
# 1
What exactly have you tried? That is, what isn't working? do you get an exception? Does the code ever run? Does it simply not enable the toolbar?
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
ok, what i tried was to do this. My form1 was a MDI parent. I would the have my main method create form1 which then created the login form as a child. I would then login and perform a test to determine which toolbar to use, but I was unable to pass the variable back down to the MDI parent and make the proper toolbar visible.

I hope this makes sense.

I will try once more - I have a MDI app, create a MDI child login screen which tells the MDI parent which toolbar to make visible to the user. But my problem is the communication between the MDI child and the MDI parent. I cannot make this work.

What I have done to get by is to create a SDI application instead and starting the application with this code

[STAThread]
static void Main()
{
Login frmLogin = new Login();
frmLogin.Show();
Application.Run();
}

I think I actually might be better off using SDI for my application as I am determining which Main screen to load based on the login security level. This is working fine and I am able to load the correct SDI form based on security level. I was hoping to try to contain all forms inside a MDI container but I couldn't make it work.

Any help you could give on the MDI parent/ child communication would be great

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
Sorry Ken, to answer your questions. Yes, it works except for the toolbar not becoming visible. The code does run, except for the toolbar not becoming visible...
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
To pass a value from a child form to the parent form, create a public property in the parent form, and then from the child form, use code like the following to set it:

Me.MdiParent.SomeProperty = someValue

Then, in the Property Set procedure of SomeProperty in the parent form, you can run code to enable to correct toolbar.

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5
another way is to define a custom event for the child form, and let the parent has the reference to the child , hook the event from the parent .

child

public event EventHandler OnLoggedOn;

// a helper method to fire the event , say a login button clicked
void btnLogin_Clicked(object obj, EventArgs args)
{
if( null != OnLoggedOn)
OnLoggedOn(this, new EventArgs());


}

while in the parent

public parent(){
// constructor in parent
// assuming child is the reference to the child form
child.OnLoggedOn += new EventHandler(LoadToolBar);
}

void LoadToolBar(object sender, EventArgs args)
{
// here's where you load it
}

the example just show you the empty eventargs , you could create a custom event args accordingly and define your own delegate

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6
Thanks to both of you. Now I can do what I orginally set out to do.
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...