添加圆角矩形类
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Runtime.InteropServices
Imports System.Text
Namespace RounRectangle
Public Class Win32
#Region "Window Const"
Public Const WM_ERASEBKGND As Integer = &H14
Public Const WM_LBUTTONDOWN As Integer = &H201
Public Const WM_LBUTTONUP As Integer = &H202
Public Const WM_LBUTTONDBLCLK As Integer = &H203
Public Const WM_WINDOWPOSCHANGING As Integer = &H46
Public Const WM_PAINT As Integer = &HF
Public Const WM_CREATE As Integer = &H1
Public Const WM_ACTIVATE As Integer = &H6
Public Const WM_NCCREATE As Integer = &H81
Public Const WM_NCCALCSIZE As Integer = &H83
Public Const WM_NCPAINT As Integer = &H85
Public Const WM_NCACTIVATE As Integer = &H86
Public Const WM_NCLBUTTONDOWN As Integer = &HA1
Public Const WM_NCLBUTTONUP As Integer = &HA2
Public Const WM_NCLBUTTONDBLCLK As Integer = &HA3
Public Const WM_NCMOUSEMOVE As Integer = &HA0
Public Const WM_NCHITTEST As Integer = &H84
Public Const HTLEFT As Integer = 10
Public Const HTRIGHT As Integer = 11
Public Const HTTOP As Integer = 12
Public Const HTTOPLEFT As Integer = 13
Public Const HTTOPRIGHT As Integer = 14
Public Const HTBOTTOM As Integer = 15
Public Const HTBOTTOMLEFT As Integer = &H10
Public Const HTBOTTOMRIGHT As Integer = 17
Public Const HTCAPTION As Integer = 2
Public Const HTCLIENT As Integer = 1
Public Const WM_FALSE As Integer = 0
Public Const WM_TRUE As Integer = 1
#End Region
#Region "Public extern methods"
<DllImport("gdi32.dll")>
Public Shared Function CreateRoundRectRgn(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal x3 As Integer, ByVal y3 As Integer) As Integer
End Function
<DllImport("user32.dll")>
Public Shared Function SetWindowRgn(ByVal hwnd As IntPtr, ByVal hRgn As Integer, ByVal bRedraw As Boolean) As Integer
End Function
<DllImport("gdi32.dll", EntryPoint:="DeleteObject", CharSet:=CharSet.Ansi)>
Public Shared Function DeleteObject(ByVal hObject As Integer) As Integer
End Function
<DllImport("user32.dll")>
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
<DllImport("user32.dll")>
Public Shared Function ReleaseCapture() As Boolean
End Function
#End Region
End Class
End Namespace
窗体代码:创建方法
Private Sub SetFormRounRectRgn(form As Form, rgnRadius As Integer)
Dim hRgn As Integer = 0
hRgn = Win32.CreateRoundRectRgn(0, 0, form.Width + 1, form.Height + 1, rgnRadius, rgnRadius)
Win32.SetWindowRgn(form.Handle, hRgn, True)
Win32.DeleteObject(hRgn)
End Sub
在Form_Load里面写上
SetFormRounRectRgn(Me, 40)
原文为C#编写,文章地址
https://blog.youkuaiyun.com/wangzl1163/article/details/73859048