Groups | Blog | Home
all groups > vb.net controls > june 2005 >

vb.net controls : background color with MouseEnter event handler


Jason
6/6/2005 9:54:07 AM
Greetz

I'm tring to do something simple, such as change the background color of a
simple button when mouse enters the button area. Below is what I've got, I
don't get any errors, but the background color never changes. Is something
I'm doing wrong?

Thanks for your help.



Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.MouseEnter

Button1.BackColor = Color.FromArgb(5, Button1.BackColor)

End Sub



Ken Tucker [MVP]
6/6/2005 6:58:04 PM
Hi,

You are trying to change the buttons back color to a see through
version of its own color. Try something like this instead.

Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.MouseEnter

Button1.BackColor = Color.Blue

End Sub

Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.MouseLeave

Button1.BackColor = SystemColors.Control

End Sub



Ken

-------------------------------

[quoted text, click to view]
Greetz

I'm tring to do something simple, such as change the background color of a
simple button when mouse enters the button area. Below is what I've got, I
don't get any errors, but the background color never changes. Is something
I'm doing wrong?

Thanks for your help.



Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.MouseEnter

Button1.BackColor = Color.FromArgb(5, Button1.BackColor)

End Sub




AddThis Social Bookmark Button