【【【【vb 多边形窗体,追加分!!!】】】】

怎么制作这样一个窗体,速度啦,我追加分,谢谢了

有两种方法可实现:
1、剪裁窗体:用CreateRectRgn创建一个长方形区域,再用CreateEllipticRgn创建一个圆形区域,然后用CombineRgn合并两个区域,最后用SetWindowRgn把合并后的区域作为剪裁区作用到窗体上即可。这是正统的方法,不过稍微有点复杂,而且要创建不规则的窗体就比较吃力了。
2、颜色透明法:就是把窗体上指定的颜色所在窗体变为透明的,就像PhotoShop中的抠图一样,把不要的部分去掉,剩下的就是需要的形状了。所以你可以制作一张图片,把窗体所需形状的颜色设为白色(或其他想要的颜色),把需要裁去的部分设为某种纯色(比如纯红色、纯黄色、纯蓝色等),然后把此图片作为窗体的背景图片,再在窗体加入如下代码(这里用纯黄色作为剪裁色):
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal HWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal HWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal HWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1

Private Sub Form_Load()
Dim rtn As Long
rtn = GetWindowLong(Me.HWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong Me.HWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes Me.HWnd, &HFFFF&, 0, LWA_COLORKEY
End Sub
就可以了。
这是一种取巧的方法,相对比较简单,而且可以做出任意形状的复杂窗体,我推荐这种方法
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-09-11
1.坐标单位是Twips还是数像?
2.那个圆的半径96却比巨型边长64短?怎么回事?
3.先加分...留个E-mail发程序给你
第2个回答  2011-09-11
Option Explicit

Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As POINTAPI, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
'创建一个由一系列点围成的区域。windows在需要时自动将最后点与第一点相连以封闭多边形

Public Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private MyRegion As Long

Private Sub Form_Load()
Dim point(9) As POINTAPI
point(0).X = 145
point(0).Y = 76
point(1).X = 131
point(1).Y = 117

point(2).X = 90
point(2).Y = 117
point(3).X = 121
point(3).Y = 142

point(4).X = 107
point(4).Y = 185
point(5).X = 145
point(5).Y = 159

point(6).X = 182
point(6).Y = 185
point(7).X = 168
point(7).Y = 142

point(8).X = 200
point(8).Y = 117
point(9).X = 159
point(9).Y = 117

MyRegion = CreatePolygonRgn(point(0), 10, 1)
Me.ScaleMode = 3
Me.Move ScaleX(110, vbPixels, vbTwips), ScaleX(96, vbPixels, vbTwips), ScaleX(230, vbPixels, vbTwips), ScaleX(210, vbPixels, vbTwips)
Call SetWindowRgn(Me.hWnd, MyRegion, True)

End Sub

Private Sub Timer1_Timer()
Form1.BackColor = RGB(255 * Rnd, 255 * Rnd, 255 * Rnd)
End Sub
相似回答
大家正在搜