Activate event of multiple child in MDI

G

Guest

Create two mdi child forms to a MDI form
use the activated event to modify the text of both children (i.e. change title)
start the application
guess what
the activated event of either form will execute if that form is activated first but the other forms a ctivated event will never fire

Stopping and restarting the app will allow the other forms activated event to fire proeventing the activated event of the other form from ever executing (until the application is restarted)

comment the form2.mdichild = me for both forms

the activated event for both forms will execute

Can anyone tell me how I can get the activated event of all mdichild forms to execute when that form is activated

MDI code
fm3.MdiParent = Me
fm3.Show()

child code (form3_activated for third form)
Private Sub Form2_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Me.Text = "Form Two"
End Sub

Private Sub Form2_MdiChildActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.MdiChildActivate
Me.Text = "Second Form"
End Sub
 
G

Guest

Although you haven't given the code which is not working,what I understand about the problem is as follows:
(1) One MDI container form (say, Form1) has two MDI Children Forms (say Form2 and Form3)
(2) You want to change text of Form2 and Form3 through the respective form's activated events
(3) Also want to try MdiChildActivate event for the same purpose, that is changing the text of MDI children forms.

Here is a part of code (C#) that works:
Form1_Load():
fm2 = new Form2();
fm3 = new Form3();
fm2.MdiParent = this;
fm3.MdiParent = this;
fm2.Show();
fm3.Show();

Form2_Activated(): (Similarly, Form3_Activated())
this.Text = "Form Two"

Form1 is the application startup object. So as soon as you start the application, Form1 is loaded, which creates Form2 and Form3 objects and their activated events are fired, which result in change in their title-bar text.

Alternatively you can also write code to Form1_MdiChildActivate() (Note that Form1 is the MDI Container form) as follows:

foreach (System.Windows.Forms.Form mdiChild in this.MdiChildren)
mdiChild.Text += " : MDI Child";

This will add the phrase " : MDI Child" to each of the child form's text, That is, Form2 text will be 'Form2 : MDI Child'

Hope this helps. Converting code from C# to VB.NET should be easy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top