VB.NET构建圆角平滑的矩形控件(示例Panel)
2007-11-14 02:58
1371 查看
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
相关文章推荐
- vb.net中获取圆角矩形的两种方法
- VB.NET控件数组示例2则 (转载)
- [VB.net][WinForm]Panel控件移动\鼠标拖动
- 【搬运】VB.NET控件数组示例2则
- 章鱼哥出品—VB.NET 如何绘制圆角矩形,并适应窗体大小
- 实现让一个控件跟着鼠标一起移动? vb.net
- VB.NET中DataGridView控件
- Ajax.Net--ScriptManager和UpdatePanel控件
- vb.net 教程 3-11 窗体控件综合编程 1
- asp.net中调用javascript函数实现多功能日期控件示例
- UpdatePanel和asp.net中FileUpload控件是不兼容的
- vb.net控制TextBox控件只能输入数值型字符串
- VB.net利用LuaInterface运用Lua编程示例
- n[VB.NET]使用Splitter控件
- 发布二个asp.net 2.0控件(MessagePanel and CollapsiblePanel)
- 【iOS开发-57】案例改进:block动画、控件的removeFromSuperview、利用layer设置圆角矩形以及代理模式运用
- [VB.NET源码]77_DataView控件
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- 第三篇: UpdatePanel 控件示例
- VB.NET中DataGridView控件