带有轮廓的自定义圆形按钮
Custom rounded button with outline
我正在尝试创建一个自定义按钮宽度圆角和一个遵循其形状的白色轮廓。在 OnPaint 事件中,我添加了以下代码。
Public Class RoundedButton
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
Dim grPath As GraphicsPath = New GraphicsPath(FillMode.Winding)
grPath.AddArc(0, 0, ClientSize.Height, ClientSize.Height, 90, 180)
grPath.AddLine(grPath.GetLastPoint, New Point(ClientSize.Width - grPath.GetLastPoint.X * 2, 0))
grPath.AddArc(New RectangleF(grPath.GetLastPoint, New Size(ClientSize.Height, ClientSize.Height)), 270, 180)
grPath.CloseFigure()
Me.Region = New Region(grPath)
Dim mypen As New Pen(Color.White, 2)
mypen.Alignment = PenAlignment.Inset
e.Graphics.DrawPath(mypen, grPath)
End Sub
End Class
如果我尝试在表单中使用它,只有当背景颜色 属性 设置为透明时它才有效。如果不是,我看不到笔路径。
我想在不松动笔的圆形白色边框的情况下更改背景颜色。
我想获得这样的东西:
对于所有需要自定义按钮的项目,通常最简单的方法是用按钮图片弯曲 PictureBox,然后使用编码语言(VB.NET、C#、C++)添加点击按钮执行动作的函数。
这是一个使用 VB.NET 的小例子:
Private Sub pictureBox1_Click(sender As Object, e As EventArgs) Handles pictureBox1.Click
Process.start("http://whosebug.com")
End Sub
希望我有所帮助,
马特
我正在尝试创建一个自定义按钮宽度圆角和一个遵循其形状的白色轮廓。在 OnPaint 事件中,我添加了以下代码。
Public Class RoundedButton
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
Dim grPath As GraphicsPath = New GraphicsPath(FillMode.Winding)
grPath.AddArc(0, 0, ClientSize.Height, ClientSize.Height, 90, 180)
grPath.AddLine(grPath.GetLastPoint, New Point(ClientSize.Width - grPath.GetLastPoint.X * 2, 0))
grPath.AddArc(New RectangleF(grPath.GetLastPoint, New Size(ClientSize.Height, ClientSize.Height)), 270, 180)
grPath.CloseFigure()
Me.Region = New Region(grPath)
Dim mypen As New Pen(Color.White, 2)
mypen.Alignment = PenAlignment.Inset
e.Graphics.DrawPath(mypen, grPath)
End Sub
End Class
如果我尝试在表单中使用它,只有当背景颜色 属性 设置为透明时它才有效。如果不是,我看不到笔路径。
我想在不松动笔的圆形白色边框的情况下更改背景颜色。
我想获得这样的东西:
对于所有需要自定义按钮的项目,通常最简单的方法是用按钮图片弯曲 PictureBox,然后使用编码语言(VB.NET、C#、C++)添加点击按钮执行动作的函数。
这是一个使用 VB.NET 的小例子:
Private Sub pictureBox1_Click(sender As Object, e As EventArgs) Handles pictureBox1.Click
Process.start("http://whosebug.com")
End Sub
希望我有所帮助, 马特