JohnJDB

Hi all,

I have a mdi application in which a user can open a form using a menu or toolbar.

WHen the user opens the form the toolbar and menu have their checked status set to True. This works great.

However, when I close the child form, the menu & toolbar items are still set as checked status = true.

How can I set the checked status of the menu & toolbar buttons from the closing child form

Many thanks

John



Re: Windows Forms General Set Checked property on parent form toolbar when child form closes

nobugz

Add an event handler for the child's FormClosed event so you can remove the check. For example:

private Form2 mChild;
private void childToolStripMenuItem_Click(object sender, EventArgs e) {
if (mChild != null) mChild.Focus();
else {
mChild = new Form2();
mChild.FormClosed += ChildClosed;
mChild.MdiParent = this;
mChild.Show();
childToolStripMenuItem.Checked = true;
}
}
private void ChildClosed(object sender, FormClosedEventArgs e) {
mChild = null;
childToolStripMenuItem.Checked = false;
}






Re: Windows Forms General Set Checked property on parent form toolbar when child form closes

JohnJDB

Hiya,

Do you mean add an event handler on the Parent form or on the child form

I already had a function that was called on the child form when the child form was closed.

However I dont know how to reference the toolbar item on the parent form from the child form.

(In vb!)

Cheers

John





Re: Windows Forms General Set Checked property on parent form toolbar when child form closes

nobugz

Use the code I posted in the parent form. "Form2" is the child form.





Re: Windows Forms General Set Checked property on parent form toolbar when child form closes

JohnJDB

Hiya Hans,

in your code

private Form2 mChild;
private void childToolStripMenuItem_Click(object sender, EventArgs e) {
if (mChild != null) mChild.Focus();
else {
mChild = new Form2();
mChild.FormClosed += ChildClosed;
mChild.MdiParent = this;
mChild.Show();
childToolStripMenuItem.Checked = true;
}
}
private void ChildClosed(object sender, FormClosedEventArgs e) {
mChild = null;
childToolStripMenuItem.Checked = false;
}

is the event handler bit

mChild.FormClosed += ChildClosed;

I'm not used to the above format as I use VB.

I'd be grateful if someone could show how to add the event in VB syntax.

Cheers

John





Re: Windows Forms General Set Checked property on parent form toolbar when child form closes

nobugz

Here's the same code in VB.NET syntax:

Public Class Form1
Private mChild As Form2
Private Sub ChildToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChildToolStripMenuItem.Click
If mChild IsNot Nothing Then
Form2.Focus()
Else
mChild = New Form2
AddHandler mChild.FormClosed, AddressOf ChildClosed
mChild.MdiParent = Me
mChild.Show()
ChildToolStripMenuItem.Checked = True
End If
End Sub
Private Sub ChildClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
mChild = Nothing
ChildToolStripMenuItem.Checked = False
End Sub
End Class






Re: Windows Forms General Set Checked property on parent form toolbar when child form closes

JohnJDB

Many thanks for your help. THis is great. Even helps me towards figuring out how Events work!

Cheers

John