Creating transparent user control with mouse events
Hi,
I've been struggling with this one for a while. I would like to create a usercontrol (activex/ocx) that is transparent but still registers the mousemove event in the transparent regions of the control.
If you create a control and set backstyle to transparent then the mouse events do not fire in the transparent areas of the control.
I have tried using windows api calls to set the control to be transparent (using SetLayeredWindowAttributes) but that doesn't seem to work on a user control...
I need this control so that I can add a transparent control to the application but still track the mousemove and click events.
Re: Creating transparent user control with mouse events
ok.. i'm test it... but without resolts...
my sugestion is using API functions for catch the mouse then i think that you can resolve the problem...
i hope help you
Re: Creating transparent user control with mouse events
ok.. almost finish...
i put a timer for read the mouse position(until here normal), but now i must see if the mouse is in the UC(my problem here is that the mouse position is in screen and not in form ou UC)... heres the project try see if you can complete it...
the colisionprecise funtion is for test if the mouse is in UC or not.... but like i said, i having problem to catch the mouse position in form....
i hope help you more
Re: Creating transparent user control with mouse events
Originally Posted by LeeGarland
Thanks, I'll see if i can get it working...
for resolve the problem, i think these way:
-i know the mouse position in screen(coord variable type);
-i know the form position(extender.container.left and extender.container.top);
-the i subtract the mouse position with form position(i think that these way i catch the mouse position in form);
-then i test if the mouse position is in UC, by using my function.
these is my thinking, but i cound't put it to work(i needed more time)... but try you
Re: Creating transparent user control with mouse events
finaly... i think that i resolve the problem
in timer change the code for these:
Code:
Private Sub Timer1_Timer()
Dim coord As POINT_TYPE ' receives coordinates of cursor
Dim retval As Long ' return value
retval = GetCursorPos(coord)
Dim x As Long
Dim y As Long
x = coord.x * Screen.TwipsPerPixelX - Extender.Container.Left
y = coord.y * Screen.TwipsPerPixelY - Extender.Container.Top
If CollisionPrecise(Extender.Left, Extender.Top, UserControl.Width, UserControl.Height, x, y, 1, 1) = True Then
RaiseEvent MouseMove(x, y)
End If
End Sub
then test it and tell me something(in these case you don't know what mouse button was clicked, but we are in good way)....
i hope resolve your problem
Re: Creating transparent user control with mouse events
Originally Posted by LeeGarland
It is! Thankyou! Is there anyway of getting the mouseup working?
Thankyou for your effort on this!
and mousedown too
Code:
Private Declare Function GetCursorPos Lib "user32.dll" (lpPoint As POINT_TYPE) As Long
'Event Declarations:
Event MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseUp
Event MouseMove(x As Long, y As Long, Button As MouseButtons)
Event MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseDown
Type POINT_TYPE
x As Long
y As Long
End Type
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Enum MouseButtons
None = -1
Left = 0
Right = 1
Middle = 2
End Enum
Private Sub Timer1_Timer()
Dim coord As POINT_TYPE ' receives coordinates of cursor
Dim retval As Long ' return value
retval = GetCursorPos(coord)
Dim x As Long
Dim y As Long
Dim mousebutton As MouseButtons
x = coord.x * Screen.TwipsPerPixelX - Extender.Container.Left
y = coord.y * Screen.TwipsPerPixelY - Extender.Container.Top
If GetAsyncKeyState(vbLeftButton) Then
mousebutton = 0
ElseIf GetAsyncKeyState(vbRightButton) Then
mousebutton = 1
ElseIf GetAsyncKeyState(vbMiddleButton) Then
mousebutton = 2
Else
mousebutton = -1
End If
If CollisionPrecise(Extender.Left, Extender.Top, UserControl.Width, UserControl.Height, x, y, 1, 1) = True Then
RaiseEvent MouseMove((x - Extender.Left), (y - Extender.Top), mousebutton)
End If
End Sub
these code detect when the mouse button is pressed...