关于用VB做更漂亮的窗体的思考

2009-05-12 22:24:41来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

首先申明:以下纯属个人观点!

近来VB版中有一部分人问关于界面的美化问题.其实作为一个菜鸟.我也无法提供很专业的代码给大家.想必大家对如下代码应该很熟悉吧!

以下为引用的内容:
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 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
Private Const WM_NCLBUTTONDOWN = &HA1
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
--------------------------------------------Private Sub Form_Load()
Me.BackColor = &HFF0000
Dim rtn As Long
BorderStyler = 0
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, &HFF0000, 0, LWA_COLORKEY
End Sub

--------------------------------------------

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage Me.hwnd, WM_NCLBUTTONDOWN, 2, 0

End Sub


这是美化窗体的时候很好的办法,比用编程语句描述一个特殊形状的窗体要简单的多,只要选自己合意的图片即可!

我们都知道象PICTUREBOX,COMBOX,菜单,等等其实都是窗体.由此可以推出我们可以用替换法将其替换.当然这是我的设想了;毕竟我不是高手.

举个例子:

我想做一个图形化的按纽.那么我们可以用IMAGE来摸拟.用IMAGELIST放三张图片用来表示MOUSE_ON,MOUSE_DOWN,MOUSE_UP.当然如果你要求高一点可以用API来弥补其中的不足,使之更完善.

当然象CHECKBOX,OPTIONS用IMAGE来模拟都足足有余.-------------

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:一步一步安装VB.Net(图片较多,请稍等)

下一篇:基于ASP.NET MVC框架开发Web论坛应用程序