如何设置窗体中指定颜色半透明效果
如何设置窗体中指定颜色半透明效果
不是整个窗体半透明
不是指定颜色全透明
是指定颜色半透明
---------------------------------------------------
或者
直接设置picturebox半透明
---------------------------------------------------
或者
窗体指定某一颜色不透明,其他半透明
===================================================
请教任意一种方法即可~~谢谢
[解决办法]
使用API SetParent 窗体与控件 各别 "都" 可以 0-255 透明度 任你设定
Option Explicit
Private Sub Form_Load()
TransColor = vbBlue
Me.BorderStyle = 0: Me.Caption = ""
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Me.BackColor = TransColor
OldX = Picture1.Left: OldY = Picture1.Top
'***********************************
Call TransParent(Me.hWnd, TransColor, 120)
'*************************************
SetParent Picture1.hWnd, GetDesktopWindow
SetWindowLong Picture1.hWnd, GWL_EXSTYLE, GetWindowLong(Picture1.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
OldHwnd = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf WindowProc)
'************** 窗体设定总在最前
SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3
SetLayeredWindowAttributes Picture1.hWnd, TransColor, 255, LWA_COLORKEY Or LWA_ALPHA
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong Me.hWnd, GWL_WNDPROC, OldHwnd
Set Form1 = Nothing
End
End Sub
Private Sub Form_Click()
Unload Me
End Sub
Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Call ReleaseCapture
Call SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End Sub
'*********** 让窗体透明并且屏蔽颜色
Public Sub TransParent(ByVal Phwnd As Long, ByVal TColor As Long, Tlevel As Long)
On Error Resume Next
Rtn = GetWindowLong(Phwnd, GWL_EXSTYLE)
Rtn = Rtn Or WS_EX_LAYERED
SetWindowLong Phwnd, GWL_EXSTYLE, Rtn
SetLayeredWindowAttributes Phwnd, TColor, Tlevel, LWA_COLORKEY Or LWA_ALPHA '将扣去窗口中的指定颜色背景
End Sub