1

I am working on a Windows Forms MDI application which can create new child forms within itself. The parent form has a StatusLabel in a Statusstrip. I am trying to figure out how to change the StatusLabel text value of the parent form to the name of an active child form. I have created a "activated" event in the child form but I don't know how to change the parents form statusLabel from the child's forms "activated" code block.

Basically I want to change a label in the parent form to to the child forms name property.

Any help would be greatly appreciated.

1 Answers1

0

Try subscribing to the Activated event of the child form:

protected override void OnLoad(EventArgs e) {
  base.OnLoad(e);

  for (int i = 0; i < 3; ++i) {
    Form f = new Form();
    f.Activated += f_Activated;
    f.MdiParent = this;
    f.Text = "Form #" + i.ToString();
    f.Show();
  }      
}

void f_Activated(object sender, EventArgs e) {
  toolStripStatusLabel1.Text = ((Form)sender).Text;
}
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • Would this code go into the childs activated code block? –  Oct 10 '14 at 23:28
  • @danslik All of this code I am showing you is in the MDI parent. When I created the child form, I have the *parent* listening for the child's activated event. Then I can just cast the sender to a form and get the title of the form. If you want the name, you would replace the .Text for .Name (and give the form a name when you create it, which my code omitted). – LarsTech Oct 10 '14 at 23:36
  • Thank you for the help so far, I really appreciate it. –  Oct 11 '14 at 00:03