vb 在控件中将一个不透明的图片显示成半透明
我想做的就是在一副图片上,我加了一个picture控件,控件的背景图片想弄成半透明的,玩过游戏的人都应该知道的,在显示对话的时候,那个对话框就是半透明的,我想要的就是那个...
我想做的就是在一副图片上,我加了一个picture控件,控件的背景图片想弄成半透明的,玩过游戏的人都应该知道的,在显示对话的时候,那个对话框就是半透明的,我想要的就是那个效果,求方法,谢谢
能达到一样效果的也行,但是不能占用太多内存哦,,先送上50分,写好再加50分
看到了,这个是窗体及其所有控件的半透明化代码,但是和我的要求完全不合啊,我想要的是对话框一样的半透明啊,我也是用于对话框的,
只能能达到同样的效果的代码也行啊,例如能能否用一个image控件加label控件实现呢,(在image中载入半透明背景的图片,然后再在label中输入对话就可以达到同样的效果)
效果图如下图
https://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/zuiaishaxi/pic/item/46348f94fe129a05d21b7093.jpg 展开
能达到一样效果的也行,但是不能占用太多内存哦,,先送上50分,写好再加50分
看到了,这个是窗体及其所有控件的半透明化代码,但是和我的要求完全不合啊,我想要的是对话框一样的半透明啊,我也是用于对话框的,
只能能达到同样的效果的代码也行啊,例如能能否用一个image控件加label控件实现呢,(在image中载入半透明背景的图片,然后再在label中输入对话就可以达到同样的效果)
效果图如下图
https://gss0.baidu.com/7LsWdDW5_xN3otqbppnN2DJv/zuiaishaxi/pic/item/46348f94fe129a05d21b7093.jpg 展开
4个回答
展开全部
Option Explicit
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 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 Sub Form_Load()
Show
Picture1.Move 0, 0
Picture1.AutoSize = True
Dim sty As Long
sty = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
sty = sty Or WS_EX_LAYERED
SetWindowLong Me.hwnd, GWL_EXSTYLE, sty
SetLayeredWindowAttributes Me.hwnd, 0, 125, LWA_ALPHA
End Sub
不完美,仅作参考!!
你要求的效果,我弄了半天,搞不定,期待高手吧!
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 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 Sub Form_Load()
Show
Picture1.Move 0, 0
Picture1.AutoSize = True
Dim sty As Long
sty = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
sty = sty Or WS_EX_LAYERED
SetWindowLong Me.hwnd, GWL_EXSTYLE, sty
SetLayeredWindowAttributes Me.hwnd, 0, 125, LWA_ALPHA
End Sub
不完美,仅作参考!!
你要求的效果,我弄了半天,搞不定,期待高手吧!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你新建个工程 2个窗体 1个模块 窗体一包含2个label 代码如下
Private Sub Form1_Load()
Load (Form2)
Form2.Hide
ShowForm = False
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form2.Hide
ShowForm = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Form2
Unload Me
End Sub
Private Sub subShow(ByVal Align As Integer, ByVal BackColor As OLE_COLOR)
If ShowForm Then Exit Sub
With Form2
.BackColor = BackColor
.Top = Me.Top
If Align Then
.Left = Me.Left + Me.Width
Else
.Left = Me.Left - .Width
End If
.Show
End With
ShowForm = True
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call subShow(0, vbWhite)
End Sub
Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call subShow(1, 255)
End Sub
'窗体2代码
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, 0, 192, LWA_ALPHA
End Sub
'模块代码
Option Explicit
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Const WS_EX_LAYERED = &H80000
Public Const GWL_EXSTYLE = (-20)
Public Const LWA_ALPHA = &H2
Public Const LWA_COLORKEY = &H1
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Dim ShowForm As Boolean
Private Sub Form1_Load()
Load (Form2)
Form2.Hide
ShowForm = False
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form2.Hide
ShowForm = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload Form2
Unload Me
End Sub
Private Sub subShow(ByVal Align As Integer, ByVal BackColor As OLE_COLOR)
If ShowForm Then Exit Sub
With Form2
.BackColor = BackColor
.Top = Me.Top
If Align Then
.Left = Me.Left + Me.Width
Else
.Left = Me.Left - .Width
End If
.Show
End With
ShowForm = True
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call subShow(0, vbWhite)
End Sub
Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call subShow(1, 255)
End Sub
'窗体2代码
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, 0, 192, LWA_ALPHA
End Sub
'模块代码
Option Explicit
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Const WS_EX_LAYERED = &H80000
Public Const GWL_EXSTYLE = (-20)
Public Const LWA_ALPHA = &H2
Public Const LWA_COLORKEY = &H1
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Dim ShowForm As Boolean
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
好像没有什么好的办法,只能自己结合背景颜色一个像素一个像素的计算图形的颜色。
GDI+里面好像也有函数,你自己找找看,有没有方便一点的办法。
人家游戏是使用DirectX 来做的,那种实现半透明效果很容易的。
GDI+里面好像也有函数,你自己找找看,有没有方便一点的办法。
人家游戏是使用DirectX 来做的,那种实现半透明效果很容易的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询