Click through form?

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
10 posts Page 1 of 1
Contributors
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

Click through form?
Cheatmasterbw
Is there a way to make it so my form is completely transparent to mouse clicks (so the item behind my form gets clicked, and not my form?)

Thanks!
http://www.megaapps.tk/
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: Click through form?
M1z23R
I think you can perform click behind the form using api just by using MouseEvents.Location ?
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Click through form?
MrAksel
Im unsure about the usage about the SetCapture and ReleaseCapture API functions, but they might do what you want.
Code: Select all
Private Declare Function SetCapture Lib "User32.dll" (ByVal hWnd As IntPtr) As IntPtr
Private Declare Function ReleaseCapture Lib "User32.dll" () As Boolean

Start capturing:
SetCapture(ItemBehindForm.Handle)

Stop capturing:
Dim success As Boolean = ReleaseCapture()
If Not success Then
   MessageBox.Show("Failed releasing capture")
End If
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

Re: Click through form?
Cheatmasterbw
MrAksel wrote:
Im unsure about the usage about the SetCapture and ReleaseCapture API functions, but they might do what you want.
Code: Select all
Private Declare Function SetCapture Lib "User32.dll" (ByVal hWnd As IntPtr) As IntPtr
Private Declare Function ReleaseCapture Lib "User32.dll" () As Boolean

Start capturing:
SetCapture(ItemBehindForm.Handle)

Stop capturing:
Dim success As Boolean = ReleaseCapture()
If Not success Then
   MessageBox.Show("Failed releasing capture")
End If
This seems like it is what I am looking for. The only problem I have is the "ItemBehindForm.Handle" part. That code doesn't work :/
http://www.megaapps.tk/
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: Click through form?
Bogoh67
umm im not sure if this works anymore and i cant test it because im getting my computer with vb on it fixed, but you can try changing the forms properties:

1. BAckground Color: Yellow (or any solid color)
2. Foreground Color: (or font color i dont remember): Yellow (same as bg color)
3. Transparency Color: Yellow( same as fg color)
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: Click through form?
Axel
Cheatmasterbw wrote:
MrAksel wrote:
Im unsure about the usage about the SetCapture and ReleaseCapture API functions, but they might do what you want.
Code: Select all
Private Declare Function SetCapture Lib "User32.dll" (ByVal hWnd As IntPtr) As IntPtr
Private Declare Function ReleaseCapture Lib "User32.dll" () As Boolean

Start capturing:
SetCapture(ItemBehindForm.Handle)

Stop capturing:
Dim success As Boolean = ReleaseCapture()
If Not success Then
   MessageBox.Show("Failed releasing capture")
End If
This seems like it is what I am looking for. The only problem I have is the "ItemBehindForm.Handle" part. That code doesn't work :/
it should be the handle of the window
http://vagex.com/?ref=25000
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

Re: Click through form?
Cheatmasterbw
Axel wrote:
Cheatmasterbw wrote:
MrAksel wrote:
Im unsure about the usage about the SetCapture and ReleaseCapture API functions, but they might do what you want.
Code: Select all
Private Declare Function SetCapture Lib "User32.dll" (ByVal hWnd As IntPtr) As IntPtr
Private Declare Function ReleaseCapture Lib "User32.dll" () As Boolean

Start capturing:
SetCapture(ItemBehindForm.Handle)

Stop capturing:
Dim success As Boolean = ReleaseCapture()
If Not success Then
   MessageBox.Show("Failed releasing capture")
End If
This seems like it is what I am looking for. The only problem I have is the "ItemBehindForm.Handle" part. That code doesn't work :/
it should be the handle of the window
That didn't work. I think i need to put the handle of the object behind the form and under the mouse cursor.
http://www.megaapps.tk/
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: Click through form?
Axel
well afaik, hwnd means the handle of a window (HandleWiNDow, get it ?)
oh and every control is a window too lol
http://vagex.com/?ref=25000
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Click through form?
MrAksel
Cheatmasterbw wrote:
MrAksel wrote:
Im unsure about the usage about the SetCapture and ReleaseCapture API functions, but they might do what you want.
Code: Select all
Private Declare Function SetCapture Lib "User32.dll" (ByVal hWnd As IntPtr) As IntPtr
Private Declare Function ReleaseCapture Lib "User32.dll" () As Boolean

Start capturing:
SetCapture(ItemBehindForm.Handle)

Stop capturing:
Dim success As Boolean = ReleaseCapture()
If Not success Then
   MessageBox.Show("Failed releasing capture")
End If
This seems like it is what I am looking for. The only problem I have is the "ItemBehindForm.Handle" part. That code doesn't work :/
Look below for the working code, ignore the rest

ItemBehindForm is to be replaced with the name of the control that is behind your form. If it is in another process so you cant access it, you better use this code:
Code: Select all
Private Declare Function WindowFromPoint(ByVal point As POINT) As IntPtr

<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)>
Private Structure POINT
 Public X As Integer
 Public Y As Integer
End Structure


'Start capturing'

Dim pos As New POINT
Dim hWnd As IntPtr
pos.X = MouseLocation.X
pos.Y = MouseLocation.Y
hWnd = WindowFromPoint(pos)
If hWnd = IntPtr.Zero Then 
 MessageBox.Show("Failed getting handle")
 Return
End If
SetCapture(hWnd)

That would probably NOT (edit, look below for working code) work, but I have another way that might work better, ignore everything said in previous posts and just paste what is below anywhere in your form (that is to be click-through).
Code: Select all
    Protected Overrides ReadOnly Property CreateParams As System.Windows.Forms.CreateParams
        Get
            Dim params As CreateParams = MyBase.CreateParams
            params.ExStyle = WS_EX_TRANSPARENT Or params.ExStyle
            Return params
        End Get
    End Property

    Private Const WS_EX_TRANSPARENT As Integer = 32
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

Re: Click through form?
Cheatmasterbw
That code didn't work :/

EDIT: It works when the form's opacity is not 100%
Thanks :)
http://www.megaapps.tk/
10 posts Page 1 of 1
Return to “Coding Help & Support”