如何將裝載的一幅方形圖片,變成一個圓形或橢圓形的界面,其它四個角不顯示或透明
解决方案 »
- 关于VB中 Execute()的用法
- 又是vb连接access数据库问题
- OCX控件的使用许可问题!!大家帮忙
- VB中有没有功能象HTML里的<a herf="">link</a>超连接控件
- 如何获得服务器的时间?
- vb对话框最大化?
- 对vb工程如何打包成安装版(setup。exe)且控件自动注册?!!!!!!在线等待!!!!!
- 帮个忙~~~~谢谢了:)
- mschart的高级问题,要是你会,你就是高手!
- Sleep()函数提前执行,是VB的BUG么?
- 程序代码调用属性页时显示默认值
- 要用data控件连接一个access2000数据库(设有密码“xbxb”),并且,设置几个文本框绑定字段,但是在设置data的recordsource属性时,提示
x As Long
y As Long
End Type
Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Const ALTERNATE = 1 ' ALTERNATE and WINDING are
Const WINDING = 2 ' constants for FillMode.
Const BLACKBRUSH = 4 ' Constant for brush type.
Private Sub Form_Paint()
Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long
Me.Cls
' Number of vertices in polygon.
NumCoords = 3
' Set scalemode to pixels to set up points of triangle.
Me.ScaleMode = vbPixels
' Assign values to points.
poly(1).x = Form1.ScaleWidth / 2
poly(1).y = Form1.ScaleHeight / 2
poly(2).x = Form1.ScaleWidth / 4
poly(2).y = 3 * Form1.ScaleHeight / 4
poly(3).x = 3 * Form1.ScaleWidth / 4
poly(3).y = 3 * Form1.ScaleHeight / 4
' Polygon function creates unfilled polygon on screen.
' Re FillRgn statement to see results.
Polygon Me.hdc, poly(1), NumCoords
' Gets stock black brush.
hBrush = GetStockObject(BLACKBRUSH)
' Creates region to fill with color.
hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
' If the creation of the region was successful then color.
If hRgn Then FillRgn Me.hdc, hRgn, hBrush
SetWindowRgn Me.hWnd, hRgn, True
DeleteObject hRgn
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub
普通的窗体都是方方的,使用API函数可以做出一些奇怪的形状。比如,窗体是圆角矩形,在中间挖一个椭圆形的洞。 先要理解一个重要的概念:区域。区域是描述设备场景中某一块的GDI对象,每个区域都有一个句柄。一个区域可以是矩形,也可以是复杂的多边形,甚至是几个区域组织在一起。窗体默认的区域就是我们看到的矩形,当然它并非一定要用这个默认的区域现在开始,首先在窗体上做一个圆角矩形区域,这是窗体的大致轮廓。在圆角矩形里再确定一个椭圆形的区域,然后把这两个区域组织成一个区域,并设置窗体的区域为这个组织出来的区域。CreateRoundRectRgn函数用于创建一个圆角矩形区域;CreateEllipticRgn用于创建一个椭圆区域;CombineRgn函数用于将两个区域组合为一个新区域;SetWindowRgn函数允许您改变窗口的区域。使用其他的函数还可以做出其他更奇怪的窗体。源代码如下:Option Explicit' API 函数声明Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
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 CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private 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 SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long'常数声明Private Const RGN_DIFF = 4
' 目标区域被设置为两个区域不相交的部分'模块级变量声明Private OutRgn As Long
' 外边的圆角矩形区域
Private InRgn As Long
' 里边的椭圆区域
Private MyRgn As Long
' 圆角区域剪切掉椭圆区域后的区域,也是窗体最终的形状Private Sub Form_Click()
If OutRgn <> 0 And InRgn <> 0 And MyRgn <> 0 Then Exit Sub
Dim w As Long, h As Long
w = ScaleX(Form1.Width, vbTwips, vbPixels)
h = ScaleY(Form1.Height, vbTwips, vbPixels)
MyRgn = CreateRectRgn(0, 0, 0, 0)
OutRgn = CreateRoundRectRgn(30, 30, w - 30, h - 30, 100, 100)
InRgn = CreateEllipticRgn(100, 100, w - 100, h - 100)
Call CombineRgn(MyRgn, OutRgn, InRgn, RGN_DIFF)
Call SetWindowRgn(Form1.hWnd, MyRgn, True)
Form1.BackColor = QBColor(4)
End SubPrivate Sub Form_DblClick()
Unload Form1
End SubPrivate Sub Form_Load()
OutRgn = 0
InRgn = 0
MyRgn = 0
Form1.Width = 7800
Form1.Height = 6000
End SubPrivate Sub Form_Unload(Cancel As Integer)
If MyRgn <> 0 Then DeleteObject MyRgn
If OutRgn <> 0 Then DeleteObject OutRgn
If InRgn <> 0 Then DeleteObject InRgn
End Sub这个程序运行后,在窗体上单击,窗体就会变形,双击窗体程序结束。
要注意的是,在卸载窗体时,用DeleteObject函数删除已定义的区域。
下载地址:
http://soft.0zones.com/SoftView/SoftView_8872.html
官方描述:VB Shaped Form Creator is a program which allows you to create
shaped forms for Visual Basic 4 and 5, C# (.net), Delphi and C++.
有熟練DX的高手請指教