vb.net窗体半透明 vbnet web窗体-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

vb.net窗体半透明 vbnet web窗体

VB.NET 2005 如何做部分窗体透明

简单的部分透明比较难做,不过可以换个方式考虑一下。

创新互联服务项目包括武定网站建设、武定网站制作、武定网页制作以及武定网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,武定网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到武定省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

把本问题转换成在VB.NET 2005环境下创建不规则窗体(=普通窗体 - 透明部分)问题,解决方法就很多了,网上也有许多例子。如 章立民 的书里就详细讲过。

大致思路如下:

1。将backgroundimage设成一个位图(点阵图)

2.将Transparaencykey设成位图的背景颜色(位图最取背景单纯,单纯部分将成为透明部分)

3.如需要可以将formborderstyle设为none,会移除标题栏,并需要手动编写窗体移动、关闭等动作代码,

半透明,请问在VB中如何使一个窗体半透明

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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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 gwl_exstyle = -20

Private Const lwa_alpha As Long = H2

Private Const ws_ex_layered As Long = H8000

Private Sub Form_Load()

Dim Fattri As Long

Call SetWindowLong(Me.hwnd, gwl_exstyle, Fattri Or ws_ex_layered)

Call SetLayeredWindowAttributes(Me.hwnd, 0, 200, lwa_alpha)

End Sub

vb窗体半透明了 但是文本框输入的字也半透明了

你不用反复问这个问题了,VB很难实现的。要么窗体整体半透明(用LWA_ALPHA常数指定透明度),要么就窗体完全透明,控件不透明(用LWA_COLORKEY常数指定透明色)。不过你可以把两种窗体结合使用,就是用一个半透明的窗体做背景,上面覆盖一个同样大小的完全透明(控件不透明)的窗体,曲线实现你的目的。

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 WS_EX_TRANSPARENT = H20

Private Const LWA_ALPHA = H2

Private Const LWA_COLORKEY = H1

Private Sub Form_Load()

Dim rtn As Long, ctrol As Control

rtn = GetWindowLong(hwnd, GWL_EXSTYLE)

rtn = rtn Or WS_EX_TRANSPARENT

SetWindowLong hwnd, GWL_EXSTYLE, rtn

Me.Show

DoEvents

For Each ctrol In Me.Controls

ctrol.Refresh

Next

'SetLayeredWindowAttributes hwnd, 0, 100, LWA_ALPHA '100值可调,0-255之间,越小透明度越高

'SetLayeredWindowAttributes hwnd, RGB(0, 0, 0), 0, LWA_COLORKEY '将窗体上的黑颜色去掉

End Sub

如何用VB实现半透明控件

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong 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 SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Sub SetFormTranslucency(hwnd As Long, crKey As Long, bAlpha As Byte, dwFlags As Long)'实现半透明窗体

Dim rtn As Long

rtn = GetWindowLong(hwnd, GWL_EXSTYLE)

rtn = rtn Or WS_EX_LAYERED

SetWindowLong hwnd, GWL_EXSTYLE, rtn

SetLayeredWindowAttributes hwnd, crKey, bAlpha, dwFlags

End Sub

Private Sub Form_Load()

Call SetFormTranslucency(Me.hwnd, 0, 200, 2) '窗体半透明,200为透明值

End Sub

可以实现窗体和窗体上的控件全都半透明,透明度可调

在vb中,如何把半透明窗体(仿Vista)应用于同一程序所有的窗体,使它们都变成半透明的

添加一个公共模块 添加如下代码

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

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 = H1

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

再在每一个窗体的代码上添加如下代码

注意,窗体上有三个控件,text1,command1,label1,这些都是半透明的

Private Sub Form_Load()

Me.BackColor = vbWhite

Text1.BackColor = vbWhite

Command1.BackColor = vbWhite

Label1.BackColor = vbWhite

Dim rtn As Long

rtn = GetWindowLong(hwnd, GWL_EXSTYLE)

rtn = rtn Or WS_EX_LAYERED

SetWindowLong hwnd, GWL_EXSTYLE, rtn

SetLayeredWindowAttributes hwnd, vbWhite, 150, 2 '最后一个参数为 1 时, 是 挖去 第二个参数指定的色,第3个设置透明度的参数无效, 最后一个参数为 2时,第2个参数无效,第3个参数有效 设置透明度范围 【0,255】

End Sub

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

我没用过vista,不知是否是同一个效果


分享文章:vb.net窗体半透明 vbnet web窗体
链接分享:http://kswsj.cn/article/hhhocg.html

其他资讯