button background colour on mouse enter event

ninjaimp

Well-known member
Joined
Jun 13, 2007
Messages
80
Programming Experience
1-3
I trying to create some, what i thought, simple rollover buttons. everything works fine except that the background colour on the mouse enter is always different to what i set.

I have tried all the different flat settings on if set to 'flat' the background colour allways appears different despite to to directly set the colour - if i set the flat to 'popup' then the background colour changes fine but the borders go all funny on the mouse enter.

I just wondered if anyone had any ideas - my button code is below
cheers

VB.NET:
Private Sub Button5_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.MouseEnter
        Button5.Image = My.Resources.Left
        Button5.FlatStyle = FlatStyle.Popup
        Button5.BackColor = Color.MistyRose


    End Sub

    Private Sub Button5_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.MouseLeave
        Button5.Image = My.Resources.Left_down
        Button5.FlatStyle = FlatStyle.Popup
        Button5.BackColor = Color.MistyRose

    End Sub
 
Why are you setting the flat style in the code? In the mouse events nonetheless! Do this in the Windows Form Designer and set it to Flat.

As for the color changing, that's just default Window's behavior.

What you need to do is set UseVisualStyles to false. This will stop that behavior.

But what I would do is hide the button completely. Make the BackgroundImage change.
 
i have set the usevisualstylesbackcolor to false and is still happening!

How do i hide the button and change the backgorundimage?

thanks for your help
 
All you have to do is use Photoshop (Or Paint...) and make yourself your button that you want, then set the BackgroundImage property to the off state. Here's the code for the mouseovers.

VB.NET:
Private Sub Button5_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.MouseEnter
        Button5.BackgroundImage = My.Resources.ButtonOn

End Sub

Private Sub Button5_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button5.MouseLeave
        Button5.BackgroundImage = My.Resources.ButtonOff

End Sub

Also, I would recommend changing MouseEnter to MouseMove, since (for me anyhow) I've noticed that there's a delay of the changing of images.
 
Back
Top