I have created my own button class that inherits the Button class and I have overrode the OnPaint method so I can draw my own graphics. However, I want to be able to achieve the same effect that the button.flatstyle.flat has: where it has a mousehover and mousedown color. How can i make my button draw a different color on mousehover or mousedown?
Here is my OnPaint method:
Here is my OnPaint method:
VB.NET:
Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)
pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias
pevent.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
pevent.Graphics.Clear(Me.Parent.BackColor) 'get color from parent (fake transparency)
Dim radius As Int32 = 12
Dim buttonback As GraphicsPath = RoundRect(New Point(0), Me.Size, radius) 'draws rounded rectangle
Dim highlight As GraphicsPath = TopLeft(New Point(0), Me.Size, radius) 'draws just topleft part
Dim shadow As GraphicsPath = BottomRight(New Point(0), Me.Size, radius) 'draws just bottomright part
Dim align As New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
pevent.Graphics.FillPath(New SolidBrush(Me.BackColor), buttonback) 'set background color of button
pevent.Graphics.FillPath(New TextureBrush(BackgroundImage, WrapMode.TileFlipY), buttonback) 'fill with gradient
pevent.Graphics.DrawPath(New Pen(New SolidBrush(Color.FromArgb(90, 255, 255, 255)), 1.5), highlight) 'add highlight top
pevent.Graphics.DrawPath(New Pen(New SolidBrush(Color.FromArgb(200, 0, 0, 0)), 1.5), shadow) 'add lowlight bottom
If Me.Text IsNot Nothing Then
pevent.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), Me.DisplayRectangle, align)
End If
If Not Enabled Then 'enabled property has been overridden btw
pevent.Graphics.FillPath(New SolidBrush(Color.FromArgb(90, 0, 0, 0)), buttonback) 'darken button when disabled
End If
End Sub