Public Class Form1 '********************************************************************* '作者:章鱼哥,QQ:3107073263 群:309816713 '如有疑问或好的建议请联系我,大家一起进步 '********************************************************************* '绘制圆角矩形函数 Private Function GetRoundedRectPath(ByVal rect As Rectangle,ByVal radius As Integer) As Sy@R_301_6563@.Drawing.drawing2d.GraphicsPath rect.Offset(-1,-1) Dim RoundRect As New Rectangle(rect.Location,New Size(radius - 1,radius - 1)) Dim path As New Sy@R_301_6563@.Drawing.drawing2d.GraphicsPath path.AddArc(RoundRect,180,90) '左上角 RoundRect.X = rect.Right - radius '右上角 path.AddArc(RoundRect,270,90) RoundRect.Y = rect.Bottom - radius '右下角 path.AddArc(RoundRect,90) RoundRect.X = rect.left '左下角 path.AddArc(RoundRect,90,90) path.Closefigure() Return path End Function '绘制矩形 Private Sub DrawingRect() Dim g As Graphics = Me.CreateGraphics '定义一个画布 Dim Pen As New Pen(Brushes.DarkRed,2) '定义一个画笔 Dim Hei As Integer = Me.Height Dim WID As Integer = Me.WIDth '矩形的位置和长宽随着窗体的变化而改变 Dim Rec As New Rectangle(Int(WID / 5),Int(Hei / 5),Int(WID / 2),Int(Hei / 2)) ' g.DrawRectangle(Pen,Rec) '清楚现有的矩形 g.Clear(Me.Backcolor) g.DrawPath(Pen,GetRoundedRectPath(Rec,30)) End Sub Private Sub Form1_Paint(ByVal sender As Sy@R_301_6563@.Object,ByVal e As Sy@R_301_6563@.windows.Forms.PaintEventArgs) Handles MyBase.Paint DrawingRect() End Sub Private Sub Form1_SizeChanged(ByVal sender As Sy@R_301_6563@.Object,ByVal e As Sy@R_301_6563@.EventArgs) Handles MyBase.SizeChanged Me.InvalIDate() '此函数可引发Paint事件 End SubEnd Class
原窗体绘制:
缩小窗体时:
总结
以上是内存溢出为你收集整理的章鱼哥出品—VB.NET 如何绘制圆角矩形,并适应窗体大小全部内容,希望文章能够帮你解决章鱼哥出品—VB.NET 如何绘制圆角矩形,并适应窗体大小所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)