怎么用vb制作圆形窗体?

 我来答
匿名用户
2013-08-11
展开全部
这是代码: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 LongPrivate 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 SubPrivate 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 SubPrivate Sub Picture1_Click(Index As Integer)
End
End Sub
匿名用户
2013-08-11
展开全部
呵呵 代码多了点 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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式