尝试这个:
Public Sub RoundCorners(ByVal leftTop As Boolean, ByVal rightTop As Boolean, ByVal rightBottom As Boolean, ByVal leftBottom As Boolean)
Dim p As New Drawing2D.GraphicsPath
p.StartFigure()
p.AddArc(New Rectangle(0, 0, IIF(leftTop,40,1), IIF(leftTop,40,1)), 180, 90)
p.AddArc(New Rectangle(Button1.Width - IIF(rightTop,40,1), 0, IIF(rightTop,40,1), IIF(rightTop,40,1)), -90, 90)
p.AddArc(New Rectangle(Button1.Width - IIF(rightBottom,40,1), Button1.Height - IIF(rightBottom,40,1), IIF(rightBottom,40,1), IIF(rightBottom,40,1)), 0, 90)
p.AddArc(New Rectangle(0, Button1.Height - IIF(leftBottom,40,1), IIF(leftBottom,40,1), IIF(leftBottom,40,1)), 90, 90)
p.CloseFigure()
Button1.Region = New Region(p)
End Sub
用法
RoundCorners(true,true,true,true) //Round all corners
RoundCorners(true,false,false,false) //Round left-top corner
更新
RoundCorners
如果我们以这种方式实现该方法,那就更好了:
Public Sub RoundCorners(ByVal leftTop As Int32, ByVal rightTop As Int32, ByVal rightBottom As Int32, ByVal leftBottom As Int32)
If leftTop <= 0 Then leftTop = 1
If rightTop <= 0 Then rightTop = 1
If rightBottom <= 0 Then rightBottom = 1
If leftBottom <= 0 Then leftBottom = 1
Dim p As New Drawing2D.GraphicsPath
p.StartFigure()
p.AddArc(New Rectangle(0, 0, leftTop, leftTop), 180, 90)
p.AddArc(New Rectangle(Button1.Width - rightTop, 0, rightTop, rightTop), -90, 90)
p.AddArc(New Rectangle(Button1.Width - rightBottom, Button1.Height - rightBottom, rightBottom, rightBottom), 0, 90)
p.AddArc(New Rectangle(0, Button1.Height - leftBottom, leftBottom, leftBottom), 90, 90)
p.CloseFigure()
Button1.Region = New Region(p)
End Sub
用法
RoundCorners(40,40,40,40) //Round all corners
RoundCorners(40,0,0,0) //Round left-top corners