Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2006

Tip: Looking for answers? Try searching our database.

Enter and Leave events

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BobRoyAce - 18 Jul 2006 05:33 GMT
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)?
GAZ - 24 Jul 2006 08:13 GMT
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

>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.
[quoted text clipped - 17 lines]
> disallow the change (i.e. keep it visible and don't show the new user
> control)?
BobRoyAce - 30 Jul 2006 18:33 GMT
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?

> 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
[quoted text clipped - 7 lines]
>
> GAZ
GAZ - 31 Jul 2006 11:07 GMT
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

>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
[quoted text clipped - 16 lines]
>>
>> GAZ
BobRoyAce - 06 Aug 2006 03:29 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.