怎么用vb制作圆形窗体?
- 提问者网友:伴风望海
- 2021-05-01 13:50
- 五星知识达人网友:爱难随人意
- 2021-05-01 15:30
这是代码:
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, _
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, _
ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Sub Form_Load()
Dim a, b As Long
Dim w, h As Long
w = Form1.Width / Screen.TwipsPerPixelX
h = Form1.Height / Screen.TwipsPerPixelY
a = CreateEllipticRgn(0, 0, w, h)
b = SetWindowRgn(Me.hWnd, a, True) '设置椭圆形窗体
End Sub
Private Sub Form_Activate()
Picture1(0).Visible = True
End Sub
Private Sub Label1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Picture1(0).Visible = False
Picture1(1).Visible = False
Picture1(2).Visible = False
Picture1(3).Visible = False
Select Case Index
Case Is = 0
Picture1(0).Visible = True '鼠标所在位置图形突起
Case Is = 1
Picture1(1).Visible = True '鼠标所在位置图形突起
Case Is = 2
Picture1(2).Visible = True '鼠标所在位置图形突起
Case Is = 3
Picture1(3).Visible = True '鼠标所在位置图形突起
End Select
End Sub
Private Sub Picture1_Click(Index As Integer)
End
End Sub
- 1楼网友:琴狂剑也妄
- 2021-05-01 16:15
呵呵 代码多了点
Option Explicit Public Declare Function SetWindowRgn Lib "user32 " (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long Public Declare Function CreateRectRgn Lib "gdi32 " (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long Public Declare Function DeleteObject Lib "gdi32 " (ByVal hObject As Long) As Long Public Declare Function GetPixel Lib "gdi32 " (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long Public Declare Function CombineRgn Lib "gdi32 " (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long Private Declare Function ReleaseCapture Lib "user32 " () As Long Private Declare Function SendMessage Lib "user32 " Alias "SendMessageA " (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Const RGN_OR = 2 Private Const WM_MOVE = &HF012 Private Const WM_SYSCOMMAND = &H112 '图形窗体函数 'Form1:窗体名称 'picSource:装载图形的PictureBox控件名称 'lngTransColor:要屏蔽掉的颜色,缺省为picSource的(1,1)处的颜色值 Public Function RegionFromBitmap(Form1 As Form, picSource As PictureBox, Optional lngTransColor As Long) As Long Dim lngRetr As Long, lngHeight As Long, lngWidth As Long Dim lngRgnFinal As Long, lngRgnTmp As Long Dim lngStart As Long, lngRow As Long Dim lngCol As Long If lngTransColor& < 1 Then lngTransColor& = GetPixel(picSource.hdc, 1, 1) End If lngHeight& = picSource.Height / Screen.TwipsPerPixelY lngWidth& = picSource.Width / Screen.TwipsPerPixelX lngRgnFinal& = CreateRectRgn(0, 0, 0, 0) For lngRow& = 0 To lngHeight& - 1 lngCol& = 0 Do While lngCol& < lngWidth& Do While lngCol& < lngWidth& And GetPixel(picSource.hdc, lngCol&, lngRow&) = lngTransColor& lngCol& = lngCol& + 1 Loop If lngCol& < lngWidth& Then lngStart& = lngCol& Do While lngCol& < lngWidth& And GetPixel(picSource.hdc, lngCol&, lngRow&) <> lngTransColor& lngCol& = lngCol& + 1 Loop If lngCol& > lngWidth& Then lngCol& = lngWidth& lngRgnTmp& = CreateRectRgn(lngStart&, lngRow&, lngCol&, lngRow& + 1) lngRetr& = CombineRgn(lngRgnFinal&, lngRgnFinal&, lngRgnTmp&, RGN_OR) DeleteObject (lngRgnTmp&) End If Loop Next RegionFromBitmap& = SetWindowRgn(Form1.hWnd, lngRgnFinal&, True) End Function '移动窗体 Public Function FormMove(FormhWnd As Long) Call ReleaseCapture Call SendMessage(FormhWnd, WM_SYSCOMMAND, WM_MOVE, 0) End Function