Public Class Form1 ' ********************************************************************* ' octopus brother, qq:3107073263 Group: 30 9816713 ' If you have any questions or good suggestions please contact me, everyone progress together ' ********************************************************************* ' Draw Rounded Rectangle function Private function Getroundedrectpath (ByVal rect as Rectangle, ByVal radius as Integer) as System.Drawing. Drawing2d.graphicspath rect. Offset ( -1,-1) Dim RoundRect as New Rectangle (rect. Location, new Size (Radius-1, radius-1)) Dim path as New System.Drawing.Drawing2D.GraphicsPath path. AddArc (RoundRect, 180, 90) ' upper left corner roundrect.x = rect. Right-radius ' upper right corner path. AddArc (RoundRect, +) Roundrect.y = rect. Bottom-radius ' lower right corner path. AddArc (roundrect, 0, roundrect.x) = rect. Left ' bottom ' path. AddArc (RoundRect,,) path. Closefigure () Return path End Function ' Draw rectangle Private Sub drawingrect () Dim g as Graphics = me.cReategraphics ' defines a canvas dim Pen As New Pen (brushes.darkred, 2) ' defines a brush dim Hei as Integer = Me.height D Im Wid as Integer = Me.Width ' rectangle's position and length change as the form changes Dim Rec as New Rectangle (int (WID/5), int (HEI/5), int (Wi D/2), Int (HEI/2)) ' G.drawrectangle (Pen, Rec) ' Clear existing rectangle g.clear (me.backcolor) G.drawpath (P En, Getroundedrectpath (Rec.)) End Sub Private Sub form1_paint (ByVal sender as System.Object, ByVal e as System.wi Ndows. Forms.painteventargs) Handles mybase.paint drawingrect () End Sub Private Sub form1_sizechanged (ByVal sender A S System.Object, ByVal e as System.EventArgs) Handles mybase.sizechanged me.invalidate () ' This function can raise the paint event End Sube nd Class
Original form drawing:
When shrinking a form:
Octopus Brother produced-vb.net how to draw rounded rectangles and fit the form size