I am trying to understand Enter and Leave events for a user control. I
am using Visual Studio 2005, using VB, for a Windows Forms application.
I am showing and hiding (by changing visible property) user controls on
my main form (within a panel) based on NavBar links being clicked on. I
put code in the Enter and Leave events to simply show a message. Here's
what happens...

The first time the contol is shown, the Enter event fires.
The first time I click on another NavBarItem, the Leave event fires.
However, the control associated with the clicked on NavBarItem doesn't
show.
After that, the Enter and Leave events no longer fire when control's
visibility is changed.

So, I guess it's not the change in visibility that fires these events.
Then what does cause them to fire?

What if I want to check for certain conditions being met before I allow
a user control to be hidden (Visible=False) and, if they're not met, I
disallow the change (i.e. keep it visible and don't show the new user
control)?

Re: Enter and Leave events by GAZ

GAZ
Mon Jul 24 02:13:07 CDT 2006

Enter and Leave events are just that. They will fire when the cursor Enters
or Leaves the control. For example, if you tab through controls on a form
the Enter event will fire each time your cursor enters a textbox, and the
leave event will fire each time when you tab out of a textbox (same goes if
you click into a control with a mouse).

Simplistic but you can get the jist of it.

BR,

GAZ

"BobRoyAce" <broy@omegasoftwareinc.com> wrote in message
news:1153197226.724324.190060@b28g2000cwb.googlegroups.com...
>I am trying to understand Enter and Leave events for a user control. I
> am using Visual Studio 2005, using VB, for a Windows Forms application.
> I am showing and hiding (by changing visible property) user controls on
> my main form (within a panel) based on NavBar links being clicked on. I
> put code in the Enter and Leave events to simply show a message. Here's
> what happens...
>
> The first time the contol is shown, the Enter event fires.
> The first time I click on another NavBarItem, the Leave event fires.
> However, the control associated with the clicked on NavBarItem doesn't
> show.
> After that, the Enter and Leave events no longer fire when control's
> visibility is changed.
>
> So, I guess it's not the change in visibility that fires these events.
> Then what does cause them to fire?
>
> What if I want to check for certain conditions being met before I allow
> a user control to be hidden (Visible=False) and, if they're not met, I
> disallow the change (i.e. keep it visible and don't show the new user
> control)?
>



Re: Enter and Leave events by BobRoyAce

BobRoyAce
Sun Jul 30 12:33:59 CDT 2006

I understand what you're saying as it relates to text boxes and such.
However, what I don't understand is why the Enter and Leave events
aren't firing for the user controls that I'm hiding (see original post)
when I show another (only fire the first time).

Any ideas? Any ideas about the last part of my post?

GAZ wrote:
> Enter and Leave events are just that. They will fire when the cursor Enters
> or Leaves the control. For example, if you tab through controls on a form
> the Enter event will fire each time your cursor enters a textbox, and the
> leave event will fire each time when you tab out of a textbox (same goes if
> you click into a control with a mouse).
>
> Simplistic but you can get the jist of it.
>
> BR,
>
> GAZ


Re: Enter and Leave events by GAZ

GAZ
Mon Jul 31 05:07:02 CDT 2006

Because in order to show or hide controls you do not have to enter and/or
leave them (controls neither get nor lose focus). In order for required
events to fire you'd have to give focus to the control in question. For
example, if you had a hidden textbox and you want both to show it and to
fire the enter event you'd use this code:

TextBox1.show
TextBox1.Focus

This code will show the textbox and give it focus (i.e. fire the enter
event).

BR,

GAZ



"BobRoyAce" <broy@omegasoftwareinc.com> wrote in message
news:1154280839.836095.46210@75g2000cwc.googlegroups.com...
>I understand what you're saying as it relates to text boxes and such.
> However, what I don't understand is why the Enter and Leave events
> aren't firing for the user controls that I'm hiding (see original post)
> when I show another (only fire the first time).
>
> Any ideas? Any ideas about the last part of my post?
>
> GAZ wrote:
>> Enter and Leave events are just that. They will fire when the cursor
>> Enters
>> or Leaves the control. For example, if you tab through controls on a form
>> the Enter event will fire each time your cursor enters a textbox, and the
>> leave event will fire each time when you tab out of a textbox (same goes
>> if
>> you click into a control with a mouse).
>>
>> Simplistic but you can get the jist of it.
>>
>> BR,
>>
>> GAZ
>



Re: Enter and Leave events by BobRoyAce

BobRoyAce
Sat Aug 05 21:29:07 CDT 2006

I understand...guess I don't fully know why the events fire once except
that the first time they fire is after the control is created. After
that, it's not created again...just hidden and shown. Also, wouldn't
setting focus on any other control cause the Leave event to fire on the
control that before that had focus?

Am I correct to understand that you don't have any ideas about the last
part of my oringinal post? I could really use some help there.