Reputation: 272
I am trying to make an "overlay" application if you want to call it that. So you can see everything on the very top layer (above all applications) but you cannot interact with any of it so the mouse clicks are behind this window. I have managed to do it with the main Form with a TransparencyKey for the background color (white). But adding a PictureBox, the things that are not white on it are not transparent.
I found a solution in C# but not sure how to "translate" it or apply it to VB.net. Click through transparency for Visual C# Window Forms?
Things I have done and tried: Create a Graphic of the image instead but I was not successful. As so:
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))
Found this on MSDN and tried to use it and various other examples I found on the internet but no luck.
So overall: Is there any way to make a whole application "transparent" to mouse clicks. What is a method of making each object (such as PictureBoxes) transparent to mouse clicks. - Thanks
Upvotes: 0
Views: 684
Reputation: 31
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
Upvotes: 1