当前位置:编程学习 > C#/ASP.NET >>

如何是使vb编写的程序有透明的效果?

在win7那种常见的可调透明度的效果呢? --------------------编程问答--------------------

Partial Class Form1
 Declare Auto Function DwmIsCompositionEnabled Lib "dwmapi.dll" Alias "DwmIsCompositionEnabled" (ByRef pfEnabled As Boolean) As Integer
    Declare Auto Function DwmExtendFrameIntoClientArea Lib "dwmapi.dll" Alias "DwmExtendFrameIntoClientArea" (ByVal hWnd As IntPtr, ByRef pMargin As Margins) As Integer
    Public Structure Margins
        Public Left As Integer
        Public Right As Integer
        Public Top As Integer
        Public Bottom As Integer
    End Structure
    Dim pMargins As New Margins With {.Top = -1, .Left = -1, .Right = -1, .Bottom = -1}
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim en As Boolean = False
        If System.Environment.OSVersion.Version.Major >= 6 Then  '如果是Vista系统或以上
            DwmIsCompositionEnabled(en)  '取得是否开启了Aero效果
            If en Then
                DwmExtendFrameIntoClientArea(Me.Handle, pMargins)
            Else
                MessageBox.Show("Desktop Composition is Disabled!")
            End If
        Else '非Vista系统上的提示
            MessageBox.Show("Please run this on Windows Vista.")
        End If
        Me.TransparencyKey = Color.FromArgb(250, 250, 1)
        Me.BackColor = Me.TransparencyKey
    End Sub
End Class


--------------------编程问答-------------------- 在FORM中有个属性就是设定透明度的
--------------------编程问答-------------------- 对,在FORM中有个属性就是设定透明度的
--------------------编程问答--------------------
Me.Opcity=0.5 '50%透明度
--------------------编程问答--------------------
引用 4 楼 dylike 的回复:
VB.NET code
Me.Opcity=0.5 '50%透明度



vb.net才有的吗?我vb6.0里怎么找不到啊? --------------------编程问答-------------------- 我倒,vb6.0是没有透明属性的
只能用Image框+图片来做透明效果
半透明效果需要调用API绘图函数来绘制

win7的效果需要vb.net 里面的 WPF 应用程序才行
普通的windows应用程序没有某些Aero特效 --------------------编程问答--------------------

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

补充:.NET技术 ,  VB.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,