Creating Custom Buttons - Please Help

xjamesfx

Member
Joined
Apr 3, 2011
Messages
12
Programming Experience
Beginner
Hi,
Whenever I need to create a custom button on Visual Studio 2010, I use this code: (found in a tutorial on youtube)
Public Class BUTTON
Inherits Windows.Forms.Button
Public Sub New()
Me.Size = New System.Drawing.Point(90, 25)
Me.FlatStyle = Windows.Forms.FlatStyle.Flat
Me.BackgroundImage = My.Resources.BtnNormal
Me.BackgroundImageLayout = Windows.Forms.ImageLayout.Stretch
Me.BackColor = Drawing.Color.Transparent
Me.Font = New System.Drawing.Font("tahoma", 9.01, Drawing.FontStyle.Regular, Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ForeColor = Drawing.Color.White
Me.FlatAppearance.BorderColor = Drawing.Color.Gray
Me.FlatAppearance.MouseDownBackColor = Drawing.Color.Transparent
Me.FlatAppearance.MouseOverBackColor = Drawing.Color.Transparent
Me.FlatAppearance.BorderSize = 0
End Sub
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Me.BackgroundImage = My.Resources.BtnPressed
End Sub
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
Me.BackgroundImage = My.Resources.BtnHover
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
Me.BackgroundImage = My.Resources.BtnNormal
End Sub
Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
Me.BackgroundImage = My.Resources.BtnHover
End Sub
End Class

However this means that when the button is right clicked (or clicked with scroll wheel) it is also changed to the Pressed state (mouse down)
What could I add to this that would mean only left clicking the button made the mouse down state trigger?
Thanks
 
Check out the event information provided by the e parameter, for MouseEventArgs class you have these members: MouseEventArgs Members (System.Windows.Forms) Click into the Button property help topic to see a code example using this information.
 
  1. Open the help page I linked to.
  2. Review the properties, these provide information available in event handler.
  3. Click the link to open the help page for Button property.
  4. Review the provided code example.
 
Back
Top