我曾经使用以下代码在 VB 6.0 中更改表单形状:
Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Sub MakeRoundObject(objObject As Object, Value As Long)
Static lngHeight, lngLong, lngReturn, lngWidth As Long
lngWidth = objObject.Width / Screen.TwipsPerPixelX
lngHeight = objObject.Height / Screen.TwipsPerPixelY
SetWindowRgn objObject.hWnd, CreateRoundRectRgn(10, 50, lngWidth, lngHeight, Value + 10, Value), True
End Sub
Private Sub Form_Load()
Call MakeRoundObject(Form1, 50)
End Sub
以同样的方式,我使用 VB.NET 代码如下:
Imports Microsoft.VisualBasic.Compatibility
Public Class Form1
Private Declare Function CreateRoundRectRgn Lib "gdi32" (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
Private Declare Function ReleaseCapture Lib "user32" () As Integer
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Integer, ByVal hRgn As Integer, ByVal bRedraw As Boolean) As Integer
Private Sub MakeRoundObject(ByRef objObject As Object, ByRef Value As Integer)
Static lngLong, lngHeight, lngReturn As Object
Static lngWidth As Integer
lngWidth = objObject.Width / VB6.TwipsPerPixelX
lngHeight = objObject.Height / VB6.TwipsPerPixelY
SetWindowRgn(objObject.hWnd, CreateRoundRectRgn(0, 0, lngWidth, lngHeight, Value, Value), True)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MakeRoundObject(Me, 20)
End Sub
End Class
但在后一种情况下,我收到一条错误消息 - “未找到类型 'Form1' 上的公共成员 'hWnd'。”
我所做的?