473,467 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

User Control Events

I have a relatively minor problem that has been bugging me for a long
time. I have created a user control which consists of a few panels
and labels. What I want to do with this user control is to change its
back color when the mouse hovers over it and to change the back color
to its previous color when the mouse leaves the control creating the
illusion of the control being highlighted.

Now I assumed that after the user control was created and I plopped it
on a form, the panels and labels contained in the control we be
considered as part of the control. So inside of the user control I
handled the Me.MouseHover and Me.MouseLeave events to change the back
color. Similar code to what I had is shown below.

Private Sub myControl_MouseHover(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.MouseHover
Me.BackColor = SomeColor
End Sub

Private Sub myControl_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.MouseLeave
Me.BackColor = SomeColor2
End Sub

However I found out that when you plop a user control on a form, the
panels and labels (and other components) inside of the user control
are still considered separate from "Me", if you will. This means that
the Me.MouseHover event is only triggered when the mouse is over a
portion of the control that isn't covered by a panel, label, etc.
Moreover, this means that Me.MouseLeave is triggered when moving from
a "blank" portion of the control (a portion with no windows controls
on it) to a portion with a windows control on it (a panel or label in
my case).

I have a work around in which I handle all MouseHover and MouseLeave
events of all the components. Similar code to what I have is shown
below.

Private Sub myControl_MouseHover(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.MouseHover, Panel1.MouseHover,
Label1.MouseHover
Me.BackColor = SomeColor
End Sub

Private Sub myControl_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.MouseLeave, Panel1.MouseLeave,
Label1.MouseLeave
Me.BackColor = SomeColor2
End Sub

The problem with this is that I get a flickering effect when the mouse
leaves Panel1, for example, and enters "Me" (the empty part of the
control) or Label1. I've played around with the Modifiers property on
the labels and panels but I've had no luck. So I guess the question
inside of this long winded post is: Is there a way to get predefined
windows controls to act like they are a part of a user defined
control? I realize that one way to fix this is to just draw on the
control itself in the OnPaint and ditch the panels and labels, but it
was easy to just dock and anchor the panels and labels to
automatically resize instead of manipulating coordinates of drawn
shapes.

Any help on this is appreciated.

Thanks,
BJ

Jul 10 '07 #1
1 1929
On Jul 10, 3:09 pm, johnson...@gmail.com wrote:
I have a relatively minor problem that has been bugging me for a long
time. I have created a user control which consists of a few panels
and labels. What I want to do with this user control is to change its
back color when the mouse hovers over it and to change the back color
to its previous color when the mouse leaves the control creating the
illusion of the control being highlighted.

Now I assumed that after the user control was created and I plopped it
on a form, the panels and labels contained in the control we be
considered as part of the control. So inside of the user control I
handled the Me.MouseHover and Me.MouseLeave events to change the back
color. Similar code to what I had is shown below.

Private Sub myControl_MouseHover(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.MouseHover
Me.BackColor = SomeColor
End Sub

Private Sub myControl_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.MouseLeave
Me.BackColor = SomeColor2
End Sub

However I found out that when you plop a user control on a form, the
panels and labels (and other components) inside of the user control
are still considered separate from "Me", if you will. This means that
the Me.MouseHover event is only triggered when the mouse is over a
portion of the control that isn't covered by a panel, label, etc.
Moreover, this means that Me.MouseLeave is triggered when moving from
a "blank" portion of the control (a portion with no windows controls
on it) to a portion with a windows control on it (a panel or label in
my case).

I have a work around in which I handle all MouseHover and MouseLeave
events of all the components. Similar code to what I have is shown
below.

Private Sub myControl_MouseHover(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.MouseHover, Panel1.MouseHover,
Label1.MouseHover
Me.BackColor = SomeColor
End Sub

Private Sub myControl_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.MouseLeave, Panel1.MouseLeave,
Label1.MouseLeave
Me.BackColor = SomeColor2
End Sub

The problem with this is that I get a flickering effect when the mouse
leaves Panel1, for example, and enters "Me" (the empty part of the
control) or Label1. I've played around with the Modifiers property on
the labels and panels but I've had no luck. So I guess the question
inside of this long winded post is: Is there a way to get predefined
windows controls to act like they are a part of a user defined
control? I realize that one way to fix this is to just draw on the
control itself in the OnPaint and ditch the panels and labels, but it
was easy to just dock and anchor the panels and labels to
automatically resize instead of manipulating coordinates of drawn
shapes.

Any help on this is appreciated.

Thanks,
BJ
You could try overriding the WndProc, or any of the various Process*
and PreProcess* methods of UserControl. That should allow you to
intercept the messages to your UserControl and act accordingly.

Just a suggestion,

Chris

Jul 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
5
by: George Durzi | last post by:
I have a simple user control with a text box and a submit button. When the user enters some text into the textbox and clicks the submit button, a record is created in the database. I'm using...
10
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of...
4
by: thomson | last post by:
Hi all, i do have a user control with 4 buttons, and all the events are firing properly, My problem is that i need to right an event handler in the user control, which gets fired after a...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
6
by: Art | last post by:
Hi I'm new at this and need some help. I have a "solution" with 2 projects - the main project and a library. The library is simple, it contains a text box that will appear many times in the form...
1
by: Israel | last post by:
The problem: I want to know, definitively when a slider loses focus after a user has started sliding and hasn't released the mouse yet. It appears that this is captured with the WM_ACTIVATEAPP...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.