vb中怎样设置窗体中的控件为透明
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vb中怎样设置窗体中的控件为透明相关的知识,希望对你有一定的参考价值。
半透明也可以
参考技术A 窗体透明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
Const HWND_TOPMOST = -1
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
Dim lTime As Long
Dim lTime 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
Me.BackColor = RGB(255, 255, 255)
BorderStyler = 0
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, RGB(255, 255, 255), 100, LWA_COLORKEY
SetWindowPos Me.hwnd, HWND_TOPMOST, Me.Left / Screen.TwipsPerPixelX _
, Me.Top \ Screen.TwipsPerPixelY, Me.Width \ Screen.TwipsPerPixelX, _
Me.Height \ Screen.TwipsPerPixelY, 0本回答被提问者采纳 参考技术B 只有Label控件可以设置透明,其它都不行。 参考技术C 除了特殊几个控件,其它的没办法直接设置透明或者半透明。。。
如果要实现这些效果,需要调用系统的API来实现,具体你可以百度一下
以上是关于vb中怎样设置窗体中的控件为透明的主要内容,如果未能解决你的问题,请参考以下文章
WinForm窗体,在VS2010上背景颜色不能设置透明,我把背景颜色和TransparencyK