单击VB.net中的透明度(单击窗口后面的窗口)

时间:2015-10-29 21:30:38

标签: vb.net overlay

我正在努力制作一个"叠加"应用程序,如果你想称之为。因此,您可以在最顶层(在所有应用程序之上)查看所有内容,但您无法与其中的任何内容进行交互,因此鼠标单击此窗口后面。我已经设法使用带有TransparencyKey的主窗体进行背景颜色(白色)。但是添加一个PictureBox,其上不是白色的东西是不透明的。

我在C#中找到了一个解决方案但不确定如何"翻译"它或将其应用于VB.net。 Click through transparency for Visual C# Window Forms?

我做过的事情并尝试过: 创建图像的图形,但我没有成功。如此:

Dim imageFile As Image = Image.FromFile("MyImage.jpg")

' Create graphics object for alteration.
Dim newGraphics As Graphics = Graphics.FromImage(imageFile)

' Alter image.
newGraphics.FillRectangle(New SolidBrush(Color.Black), _
100, 50, 100, 100)

' Draw image to screen.
newGraphics.Graphics.DrawImage(imageFile, New PointF(0.0F, 0.0F))

在MSDN上发现这个并尝试使用它和我在互联网上找到的各种其他例子,但没有运气。

总的来说:有没有办法让整个应用程序变得透明"点击鼠标。什么是使每个对象(如PictureBoxes)对鼠标点击透明的方法。 - 谢谢

1 个答案:

答案 0 :(得分:1)

            Imports System.Runtime.InteropServices
            Class Form1

                Private InitialStyle As Integer
                Dim PercentVisible As Decimal
                Private Sub Form1_Load(sender As Object, e As RoutedEventArgs) Handles Form1.Load
                    InitialStyle = GetWindowLong(Me.Handle, -20)
                    PercentVisible = 0.8

                    SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20)

                    SetLayeredWindowAttributes(Me.Handle, 0, 255 * PercentVisible, &H2)

                    Me.Topmost = True
                End Sub

                <DllImport("user32.dll", EntryPoint:="GetWindowLong")> Public Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
                End Function

                <DllImport("user32.dll", EntryPoint:="SetWindowLong")> Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
                End Function

                <DllImport("user32.dll", EntryPoint:="SetLayeredWindowAttributes")> Public Shared Function SetLayeredWindowAttributes(ByVal hWnd As IntPtr, ByVal crKey As Integer, ByVal alpha As Byte, ByVal dwFlags As Integer) As Boolean
                End Function
            End Class