VB.NET构建圆角平滑的矩形控件(示例Panel)
来源:互联网 发布:换手机 备份数据 编辑:程序博客网 时间:2024/05/22 05:15
Imports System.Drawing.Drawing2D
Public Class RoundPanelClass RoundPanel
Inherits Panel
Private mMatrixRound As Integer = 8
Private mBack As Color
Public Property Back()Property Back() As Color
Get
Return mBack
End Get
Set(ByVal value As Color)
If value = Nothing Then
mBack = Control.DefaultBackColor
Else
mBack = value
End If
MyBase.Refresh()
End Set
End Property
Public Property MatrixRound()Property MatrixRound() As Integer
Get
Return mMatrixRound
End Get
Set(ByVal value As Integer)
mMatrixRound = value
MyBase.Refresh()
End Set
End Property
Private Function CreateRound()Function CreateRound(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
Dim RoundRect As New GraphicsPath
RoundRect.AddLine(rect.Left + radius - 1, rect.Top - 1, rect.Right - radius, rect.Top - 1) '顶端
RoundRect.AddArc(rect.Right - radius, rect.Top - 1, radius, radius, 270, 90) '右上角
RoundRect.AddLine(rect.Right, rect.Top + radius, rect.Right, rect.Bottom - radius) '右边
RoundRect.AddArc(rect.Right - radius, rect.Bottom - radius, radius, radius, 0, 90) '右下角
RoundRect.AddLine(rect.Right - radius, rect.Bottom, rect.Left + radius, rect.Bottom) '底边
RoundRect.AddArc(rect.Left - 1, rect.Bottom - radius, radius, radius, 90, 90) '左下角
RoundRect.AddLine(rect.Left - 1, rect.Top + radius, rect.Left - 1, rect.Bottom - radius) '左边
RoundRect.AddArc(rect.Left - 1, rect.Top - 1, radius, radius, 180, 90) '左上角
Return RoundRect
End Function
Protected Overrides Sub OnPaint()Sub OnPaint(ByVal e As PaintEventArgs)
Dim W As Integer = MyBase.Width - MyBase.Margin.Left - MyBase.Margin.Right
Dim H As Integer = MyBase.Height - MyBase.Margin.Top - MyBase.Margin.Bottom
Dim Rec As New Rectangle(MyBase.Margin.Left, MyBase.Margin.Top, W, H)
Dim Round As GraphicsPath = CreateRound(Rec, mMatrixRound)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.FillPath(DirectCast(New SolidBrush(mBack), Brush), Round)
End Sub
Protected Overrides Sub OnResize()Sub OnResize(ByVal e As System.EventArgs)
MyBase.Refresh()
End Sub
End Class
Public Class RoundPanelClass RoundPanel
Inherits Panel
Private mMatrixRound As Integer = 8
Private mBack As Color
Public Property Back()Property Back() As Color
Get
Return mBack
End Get
Set(ByVal value As Color)
If value = Nothing Then
mBack = Control.DefaultBackColor
Else
mBack = value
End If
MyBase.Refresh()
End Set
End Property
Public Property MatrixRound()Property MatrixRound() As Integer
Get
Return mMatrixRound
End Get
Set(ByVal value As Integer)
mMatrixRound = value
MyBase.Refresh()
End Set
End Property
Private Function CreateRound()Function CreateRound(ByVal rect As Rectangle, ByVal radius As Integer) As GraphicsPath
Dim RoundRect As New GraphicsPath
RoundRect.AddLine(rect.Left + radius - 1, rect.Top - 1, rect.Right - radius, rect.Top - 1) '顶端
RoundRect.AddArc(rect.Right - radius, rect.Top - 1, radius, radius, 270, 90) '右上角
RoundRect.AddLine(rect.Right, rect.Top + radius, rect.Right, rect.Bottom - radius) '右边
RoundRect.AddArc(rect.Right - radius, rect.Bottom - radius, radius, radius, 0, 90) '右下角
RoundRect.AddLine(rect.Right - radius, rect.Bottom, rect.Left + radius, rect.Bottom) '底边
RoundRect.AddArc(rect.Left - 1, rect.Bottom - radius, radius, radius, 90, 90) '左下角
RoundRect.AddLine(rect.Left - 1, rect.Top + radius, rect.Left - 1, rect.Bottom - radius) '左边
RoundRect.AddArc(rect.Left - 1, rect.Top - 1, radius, radius, 180, 90) '左上角
Return RoundRect
End Function
Protected Overrides Sub OnPaint()Sub OnPaint(ByVal e As PaintEventArgs)
Dim W As Integer = MyBase.Width - MyBase.Margin.Left - MyBase.Margin.Right
Dim H As Integer = MyBase.Height - MyBase.Margin.Top - MyBase.Margin.Bottom
Dim Rec As New Rectangle(MyBase.Margin.Left, MyBase.Margin.Top, W, H)
Dim Round As GraphicsPath = CreateRound(Rec, mMatrixRound)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.FillPath(DirectCast(New SolidBrush(mBack), Brush), Round)
End Sub
Protected Overrides Sub OnResize()Sub OnResize(ByVal e As System.EventArgs)
MyBase.Refresh()
End Sub
End Class
- VB.NET构建圆角平滑的矩形控件(示例Panel)
- [VB.net][WinForm]Panel控件移动\鼠标拖动
- vb.net中获取圆角矩形的两种方法
- 未平滑等值线的生成(VB.NET+MAPX)
- 等值线的生成(平滑)(MAPX+VB.net)
- ExtJs控件Panel面板的简单介绍及其小示例
- ExtJS控件样式的修改(示例无边框panel)
- ExtJS控件样式的修改(示例无边框panel)
- ExtJS控件样式的修改(示例无边框panel)
- ExtJS控件样式的修改(示例无边框panel)
- vb.net的ListBox控件
- VB:动态添加控件的示例
- Asp.net中的Panel控件
- Ext.NET panel控件属性
- ASP.NET-Panel容器控件
- VB.NET控件数组示例2则 (转载)
- P2P的简单示例:VB.net版
- P2P的简单示例:VB.net版
- IT专业人士必去得10个社区
- 用Google Map API自动寻找地址
- Java Portlet
- 配置YUM源
- 玩玩Spring之struts+hibernate+spring添删改查示例
- VB.NET构建圆角平滑的矩形控件(示例Panel)
- 怎样设置一个控件为容器
- 如何把一个窗体添加到容器控件中
- cccccc
- 学习Unix,Solaris的好地方
- wholesale craftwork
- wholesale discount car model.christmas gift.
- Scheme 自学教程 1
- 景深效果(Depth of Field)