round buttons in vb.net

  • Thread starter Thread starter saddy
  • Start date Start date
S

saddy

hello

i want to use round buttons in my vb.net application
how can i change rectangular buttons to round buttons


thanks
 
You will need to derive your own class from Button (or ButtonBase) and
then use the Region property to set the shape of your button. Then in
the OnPaint override, you will have to paint your button as desired.

Here is a very simple class that illustrates this:

Imports System.Drawing.Drawing2D

Public Class RoundButton
Inherits Button

Private _regionSet As Boolean = False

Protected Overrides Sub OnPaint(ByVal pevent As
System.Windows.Forms.PaintEventArgs)

Dim borderPen As New Pen(Color.Blue, 4)
Dim gp As New GraphicsPath()
gp.AddEllipse(Me.ClientRectangle)

If Not _regionSet Then
Me.Region = New Region(gp)
_regionSet = True
End If

pevent.Graphics.FillPath(Brushes.Red, gp)
pevent.Graphics.DrawPath(borderPen, gp)

gp.Dispose()
borderPen.Dispose()
End Sub

End Class

Now you will have to adjust to suit your needs. In particular, how the
button is painted for both button down and button up states as well as
the disabled state. But this should give you some ideas.

Chris
 
Back
Top