-1

In Vb.net, i changed the button backcolor on mousehover event, but on mouseleave event i cannot change the color of button to standard style. Button is looking in full silver color and missing the usual glossy look

On Mousehover event i gave Button1.BackColor = Color.Orange and on Mouseleave event i gave Button1.BackColor = Color.Silver , but could not get the default style of a button. Wat to do to get back the default style of button?

arvinth
  • 27
  • 1
  • 8
  • i am working in Winforms.. – arvinth Jan 27 '13 at 19:06
  • possible duplicate of [Restore c# winform backcolor](http://stackoverflow.com/questions/8218144/restore-c-sharp-winform-backcolor) It is the same question just different language. Just set the Button's UsevisualStyleBackColor to true. – Mark Hall Jan 27 '13 at 19:25

1 Answers1

1

Using Button1.MouseEnter will not make the button color change until mouse is steady over the button, while using Button1.MouseHover will change the button color when the color mouse just hovers over the button.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'AddHandler Button1.MouseEnter, AddressOf btn1MouseHover
    AddHandler Button1.MouseHover, AddressOf btn1MouseHover
    AddHandler Button1.MouseLeave, AddressOf btn1MouseLeave
End Sub

Private Sub btn1MouseLeave(ByVal sender As Object, ByVal e As EventArgs)
    Button1.UseVisualStyleBackColor = True
End Sub

Private Sub btn1MouseHover(ByVal sender As Object, ByVal e As EventArgs)
    Button1.BackColor = Color.Red
End Sub
Parimal Raj
  • 20,189
  • 9
  • 73
  • 110