How to prevent firing "Leave" event on open form??

B

Billy

Anyone know if this a bug in VB.NET 2002 and how to overcame that
situation?

I have a MDI form from where I call MDI child form like that:

Dim frm As New frmChild()
frm.MdiParent = Me
frm.Show()

On that child form I have some textboxes. When form show up Leave event
immediately fire in 1st textbox, but that should NOT happen in my
opinion.

Interesting is that this doesn't happen in VS 2003. Another observation
is that this doesn't happen if I open that form as non MDI child
(without "frm.MdiParent = Me" statement).

Any help or ideas how to prevent this will be very appreciated.
Regards,
Billy
 
C

Cor Ligthert

Billy,

This is the second time you ask this question and with the exact the same
text.

This is a very active newsgroup, so if somebody knows the answer you will be
answered and when it stays open some days our appreciated cleansweaper Peter
Huang will mostly search again for an answer.

When you want a quicker answer, than you can go to Microsoft support conform
the rules which exist for that.

Another approach can be to explain your problem in another way, by instance
with some code. How you create your MIDI child and what is maybe special on
your textbox.

Just my thought,

Cor
 
B

Billy

I don't know how to explain that easier. If you create a new project,
set main form as MDI container and from there call child form like I
wrote in my first post, you just have to check if leave event fires in
1st textbox when you open that child form. Maybe is problem just on my
PC?
 
C

Cor Ligthert

Billy,

Did you do this test yourself with a *new* project, when not try it and tell
me the result?
\\\form1
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.IsMdiContainer = True
Dim frm As New Form2
frm.MdiParent = Me
frm.Show()
End Sub
///
\\\form2
Private Sub TextBox1_Leave(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles TextBox1.Leave
MessageBox.Show("Hello I am leaved")
End Sub
///
I hope this helps?

Cor
 
B

Billy

I tried on brand new project. It's working if you open form2 with
Form1_Load event like you give example. But it won't work if you call
over menu or button later when main form is already displayed. Does it
work on your PC if you call form2 over menu?
 
C

Cor Ligthert

Billy,

Private Sub Form12_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.IsMdiContainer = True
Dim frm As New Form2
frm.MdiParent = Me
frm.Show()
End Sub

Private Sub MenuItem1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles MenuItem1.Click
Dim frm As New Form2
frm.MdiParent = Me
frm.Show()
End Sub
///

In this situation is twice the same form2 showed. In that the first showed
textbox looses his focus as the second form is showed and the event fires.

This logic you cannot prevent, because it happens. However you can catch
probably this situation depending on your program in your leave event by
setting a kind of switch. You can as well set the handlers programmicly,
however in your situation I would just do it with a switch

I hope this helps?

Cor
 
B

Billy

I think that this has to be a bug then, becuase if you will open form
over menu for example not as child (without frm.MdiParent = Me) then
Leave will not fire.

Regards,
Billy
 
C

Cor Ligthert

Billy,

I agree, I think that it is the best that you get as quick as possible that
bug from your program.

Cor
 
B

Billy

How you mean bug from my program? Do you say that "Leave" not fire in
your application if you open child form2 over menu or you joking from
from my problem?

If "Leave" fire with that call:
Dim frm As New frmChild()
frm.MdiParent = Me
frm.Show()

But not fire with that call (what is correct for Leave):
Dim frm As New frmChild()
frm.Show()

Then I missed something in my code. Can you tell me what?
 
C

Cor Ligthert

Billy,

In the sample I gave you it *should* fire.

To give you an other sample, maybe you understand it than.
In this sample it will not fire the first time one the menuclick. However
when without doing something else the second time the mouse button is
clicked, it *should* fire for the form created with the first click or when
that MDI form is closed. When you do this with a normal form, that form does
not loose focus when the button is again clicked (but should when it
closes).

\\\
Private Sub Form12_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.IsMdiContainer = True
End Sub

Private Sub MenuItem1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles MenuItem1.Click
Dim frm As New Form13
frm.MdiParent = Me
frm.Show()
End Sub
///.

I hope this makes it more clear,

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Billy,
Anyone know if this a bug in VB.NET 2002 and how to overcame that
situation?
Interesting is that this doesn't happen in VS 2003.

I don't know specifically, if it occurs in .NET 1.0 (VS2002) & not in .NET
1.1 (VS2003), then that would be a good indication that a bug was fixed!
Would it not?

I would "overcome the situation" by upgrading to VS.NET 2003, especially if
you have already demonstrated to yourself that the problem is resolved in
VS2003!

Remember 2003 fixed a number of bugs in the IDE, made a number of
performance improvements in the IDE, plus .NET 1.1 fixed a number of bugs
from .NET 1.0. .NET 1.1 SP1 fixed a number of bugs in the framework, plus
added a couple of handy options...

In fact I would recommend you upgrade all the way to VS.NET 2002 w/.NET 1.1
SP1.

Hope this helps
Jay
 
G

Greg Burns

In fact I would recommend you upgrade all the way to VS.NET 2003 w/.NET

:)

Wonder why everybody didn't upgrade to VS 2003 (from 2002) when MS was
practically giving it away for $25? Better question: why did MS stop
offering the upgrade price???

Greg
 
J

Jay B. Harlow [MVP - Outlook]

Greg,
Wonder why everybody didn't upgrade to VS 2003 (from 2002) when MS was
practically giving it away for $25?
I'm really not sure. I got the upgrade as part of my MSDN Universal
subscription...

I suspect its the "programming by rut" syndrome a number of developers have.
:-|
Better question: why did MS stop offering the upgrade price???
I really don't know, however I suspect it was a promotional gimmick in an
attempt to get people to upgrade...

Just a thought
Jay
 
G

Greg Burns

Cor Ligthert said:
Was it maybe because that it was a limited offer only for the USA and
Canada.

Ah, did not know that. VS 2003 felt so much like a point release. I don't
understand why MS charges for the upgrade.

Greg
 
B

Billy

Thank you for your replay Jay and also to all other, special to you
Cor. I agree that the easiest will be just upgrade to 2003, but
customer wanted that in 2002 when started and because of that I was
looking for some kind solution in 2002.

Regards,
Billy
 

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