disabling MdiParent during load causes incorrect MdiChild to be ac

K

Karen

Hi, I don't know if this is something that works as designed, or if this is
an error...

I have an MDI application that loads a few MDI Children on startup. While
it initially loads, I want to prevent the user from being able to click in
it, so I have set MdiParent.Enabled = False at the beginning of the Form_Load
event handler. I change it back to true at the end of the event handler.
While MdiParent.Enabled = False, I open my MdiChild forms.
Normally, the last MdiChild that is opened is the Active child form. But,
when I re-enable MdiParent, it changes the active child form to the first
MdiChild that was created.


Here's the sample code.

Private Sub MdiParent_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.Enabled = False
Dim child As MdiChild
For i As Integer = 1 To 5
child = New MdiChild()
child.Text = "Form " & i
child.MdiParent = Me
child.Show()
Next i
Me.Enabled = True
End Sub

This results in Form 1 being the active form, when I would expect Form 5 to
be active. If I comment out the code that disables/enables MdiParent, then
Form 5 is the active form.

Should this work this way or is it a bug? Should I be using some other way
of preventing the user from clicking in the app during load?

I can create my own variable to keep track of the most recently added form.
I was just curious if there was a better way to do this. Also, I tried using
MdiParent.ActiveMdiChild, but it is Nothing before MdiParent gets reenabled.

Thanks,
~Karen
 
A

Armin Zingler

Karen said:
Should this work this way or is it a bug? Should I be using some
other way of preventing the user from clicking in the app during load?

I can repro the behavior but it doesn't matter because Load occurs before
the Form gets visible. Consequently, during load, there is nothing to click
into. Therefore, disabling during load does not make sense.


Armin
 
A

Armin Zingler

Karen said:
Should this work this way or is it a bug? Should I be using some
other way of preventing the user from clicking in the app during load?

I can repro the behavior but it doesn't matter because Load occurs before
the Form gets visible. Consequently, during load, there is nothing to click
into. Therefore, disabling during load does not make sense.


Armin
 

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