473,503 Members | 7,578 Online
Bytes | Software Development & Data Engineering Community
+ 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 1936
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
7536
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
8135
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
9738
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
2475
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
1734
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
2493
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
1670
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
2264
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
3164
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
4804
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
7194
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
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6976
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
5566
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
4993
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
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1495
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 ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.