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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Data Labels - Round Border 0
Rounded Buttons 1
Round button from round image 2
Rounding Issue 4
Question about Crystal Reports in .NET 1
Start button 5
Excel Stop Excel from displaying rounded values 4
round button? 4

Back
Top