How to draw a rounded rectangle in VB. NET and adapt to the form size?
Public Class Form1 '************************************ * ******************************** 'Author: zhang yuge, QQ: 3107073263 group: 309816713 '. If you have any questions or suggestions, please contact me, everyone makes progress together '************************************ * the Private Function of drawing the rounded rectangle. 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) 'roundrect in the upper left corner. X = rect. right-radius 'path in the upper Right corner. addArc (RoundRect, 270, 90) RoundRect. Y = rect. bottom-radius 'Bottom right path. addArc (RoundRect, 0, 90) RoundRect. X = rect. left 'bottom Left path. addArc (RoundRect, 90, 90) path. closeFigure () Return path End Function 'draws a rectangle Private Sub DrawingRect () Dim g As Graphics = Me. createGraphics 'defines a canvas Dim Pen As New Pen (Brushes. darkRed, 2) 'defines a paint brush Dim Hei As Integer = Me. height Dim Wid As Integer = Me. width' the position and length of the Rectangle change with the form change Dim Rec As New Rectangle (Int (Wid/5), Int (Hei/5), Int (Wid/2 ), int (Hei/2) 'g. drawRectangle (Pen, Rec) 'specifies the existing rectangle g. clear (Me. backColor) g. drawPath (Pen, GetRoundedRectPath (Rec, 30) End Sub Private Sub Form1_Paint (ByVal sender As System. object, ByVal e As System. windows. forms. paintEventArgs) Handles MyBase. paint DrawingRect () End Sub Private Sub form=sizechanged (ByVal sender As System. object, ByVal e As System. eventArgs) Handles MyBase. sizeChanged Me. invalidate () 'this function can trigger the Paint event End SubEnd Class
Original form drawing:
When narrowing down the form:
How does vbnet make the control change with the size of the Form? You can help me think about it. It is best to have code.
Public Class Form1
Dim initialization control automatic size adjustment and window width ratio As Integer Dim initialization control automatic size adjustment and window height ratio As Integer
Private Sub Form1_Load (ByVal sender As System. object, ByVal e As System. eventArgs) Handles MyBase. the automatic size adjustment of the Load initialization control and the window width ratio = Me. the Width/control automatically adjusts the size. width initialization control automatic size adjustment and window height ratio = Me. height/control automatic size adjustment. height: displays the coordinates of the widget ()
End Sub
Private Sub form=resizeend (ByVal sender As Object, ByVal e As System. eventArgs) Handles Me. resizeEnd 'form=resizeend this event is automatically adjusted by the control after the window size changes. location = New Point (the control automatically adjusts the size. left, the control automatically adjusts the size. top) 'sets the initial left-position coordinate of the control and the upper-position coordinate control to automatically adjust the size. size = New Point (Int (Me. width/the automatic size adjustment of the initialization control and the window Width ratio), Int (Me. height/the automatic size adjustment of the initialization control and the Height ratio of the window) 'change the size of the control and adjust it according to the ratio of the first window
Show the coordinates of the widget position () End Sub
Private Sub: display the control's Coordinate Position () Label1.Text = "Control's top margin coordinates:" & control automatic size adjustment. top Label2.Text = "left margin coordinates of the control:" & controls auto size adjustment. left Label3.Text = "control width:" & control automatic size adjustment. width Label4.Text = "control height:" & control automatic size adjustment. height End SubEnd Class
There are still many ways to study it slowly, bro. Hope it can help you.
VBNET changes the size of the frameless window
Use Me. Width and Me. Height to change the size of the borderless form?
Public Class Form1
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Int32, ByVal nIndex As Int32) As Int32
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Int32, ByVal nIndex As Int32, ByVal dwNewLong As Int32) As Int32
Private Const GWL_STYLE As Int32 =-16
Private Const WS_THICKFRAME As Int32 = & H40000
Private Sub Form1_Load (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Load
Me. FormBorderStyle = Windows. Forms. FormBorderStyle. None
Dim style As Int32 = GetWindowLong (Me. Handle, GWL_STYLE) Or WS_THICKFRAME
SetWindowLong (Me. Handle, GWL_STYLE, style)
End Sub
End Class