Make a form "click through" or transparent to mouse events

P

Per Larsson

I have been nagging for help on this subject for quite some time now.
Finally got it sorted out by my self.
Here is the code if some one else ever need it.

'Declarations:

Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As System.IntPtr, ByVal nIndex As Integer) As
Integer

Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hwnd As System.IntPtr, ByVal nIndex As Integer, _
ByVal dwNewLong As Integer) As Integer


Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_TRANSPARENT = &H20&

'In your sub:

Private Sub Form1_load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Call SetWindowLong(Me.Handle, GWL_EXSTYLE, _
GetWindowLong(Me.Handle, GWL_EXSTYLE) _
Or WS_EX_TRANSPARENT)
End sub

I find it quite useful to show help or info in a semi transparent form
TopMost = True, that ignores the mouse and keyboard actions so you can
go on working in the underlying windows but still be able to read the
help.
You have to controle the thread from your main form, so you can make a
button to close it with.

/Per Larsson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top