Print Page | Close Window

How to detect Mouse-Events for Markup-Control?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Controls
Forum Description: Topics Related to Codejock Controls
URL: http://forum.codejock.com/forum_posts.asp?TID=12861
Printed Date: 13 September 2024 at 3:58am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to detect Mouse-Events for Markup-Control?
Posted By: Jebo
Subject: How to detect Mouse-Events for Markup-Control?
Date Posted: 05 December 2008 at 4:59am
Hi,

how can I detect if the user holds the mouse down or makes mousemoves on a markup-control?

Is there a way?



Replies:
Posted By: Jebo
Date Posted: 11 December 2008 at 12:54pm
PLEASE can you help!?


Posted By: jpbro
Date Posted: 11 December 2008 at 8:18pm
This trick seems to work:

1) Create a dummy Border object that will be the Height & Width of the MarkupLabel and give it the background colour of the underlying container.
2) Associate the Mouse events with the Border
3) Add the rest of your markup into a Container type element (e.g. StackPanel) and then set that to the Child property of the Border.

Here's an example:


Option Explicit

Public Sub MarkupLabelEnter(ByVal Sender As MarkupObject, ByVal Args As MarkupRoutedEventArgs)
   Debug.Print "Enter" & Rnd
End Sub
Public Sub MarkupLabelLeave(ByVal Sender As MarkupObject, ByVal Args As MarkupRoutedEventArgs)
    Debug.Print "Leave" & Rnd
End Sub

Public Sub MarkupLabelMouseMove(ByVal Sender As MarkupObject, ByVal Args As MarkupRoutedEventArgs)
    Debug.Print "Move" & Rnd
End Sub

Private Sub Form_Load()
   Dim lo_Context As MarkupContext
   Set lo_Context = MarkupLabel1.MarkupContext
  
   Dim lo_Border As MarkupBorder
   Dim lo_Container As MarkupStackPanel
   Dim lo_Text1 As MarkupTextBlock
   Dim lo_Text2 As MarkupTextBlock
  
   Set lo_Border = lo_Context.Parse("<Border Width='Auto' Height='Auto'></Border>")
   With lo_Border
      .AddHandler .MouseEnterEvent, "MarkupLabelEnter"
      .AddHandler .MouseLeaveEvent, "MarkupLabelLeave"
      .AddHandler .MouseMoveEvent, "MarkupLabelMouseMove"
      .Background = lo_Context.CreateSolidBrush(Me.MarkupLabel1.Parent.BackColor)
   End With
  
   Set lo_Container = lo_Context.CreateObject("StackPanel")
  
   Set lo_Text1 = lo_Context.CreateObject("TextBlock")
   With lo_Text1
      .Background = lo_Context.CreateSolidBrush(vbWhite)
      .Text = "Object above mouse event lo_Border object shouldn't block events."
   End With
  
   Set lo_Text2 = lo_Context.CreateObject("TextBlock")
   With lo_Text2
      .Background = lo_Context.CreateSolidBrush(vbGreen)
      .Text = "Another Object above mouse event lo_Border object shouldn't block events."
   End With
  
   lo_Container.Children.Add lo_Text1
   lo_Container.Children.Add lo_Text2
  
   Set lo_Border.Child = lo_Container
  
   Set MarkupLabel1.MarkupUIElement = lo_Border
   lo_Context.SetHandler Me
End Sub


What I don't know is if the MouseMoveEvent exposes the X & Y coordinates of the mouse (and if so, I don't know how to retrieve that information). You might have to get the mouse position using the API and convert it to appropriate coordinates relative to your form & MarkupLabel control.


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6



Posted By: Jebo
Date Posted: 12 December 2008 at 8:25am
Realy not bad! ;-)

Thank you!!!


Posted By: jpbro
Date Posted: 12 December 2008 at 1:51pm
Glad to help...hacky, but it seems to work ;)

-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net