[RESOLVED] UserControl Events Problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] UserControl Events Problem

  1. #1
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    [RESOLVED] UserControl Events Problem

    I have a User control with a label on it. If I raise a user control click event from the label it works fine. If I raise a user control dblclick event from the label it works fine. If I raise both user control events from their respective label events, then I only receive the click event. If I fire off a msgbox from the user control click event and another from the dblclick event then when I double click the label at runtime I get the msgbox for the click event and a quick flash of the msgbox indicating that a second click event was raised.

    I assume this is a timing issue, and I have attempted (albeit unsuccessfully) to implement a click count routine in conjunction with a timer control, but even if it had worked it seems like a cludge anyway.

    So for the sake of learning, hypothetically what if I needed the ability to have MouseUp, MouseDown, Click and Doubleclick events? Even my Mouse up and mousedown events are superseded by the click event.

    Any help would be appreciated.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: UserControl Events Problem

    Welcome to the Forums!

    Good question

    You need to determine the Doubleclick speed with the GetDoubleClickTime API. Then, you need to set a Timer's Interval to that time. You also need to create a Boolean variable and set it to True on Double Click, and False in Click. You then, need to use the Timer's Timer event to do whatever.

    Here is the code :
    Code:
    Private Declare Function GetDoubleClickTime Lib "user32.dll" () As Long
    Private Declare Function SetDoubleClickTime Lib "user32.dll" (ByVal wCount As Long) As Long
    
    Private MouseDBlClicked As Boolean
    
    Private Sub Form_Load()
        Timer1.Interval = GetDoubleClickTime
    End Sub
    
    Private Sub Label1_Click()
        Timer1.Enabled = True
        MouseDBlClicked = False
     
    End Sub
    
    Private Sub Label1_DblClick()
        MouseDBlClicked = True
    
    End Sub
    
    Private Sub Timer1_Timer()
    
    If MouseDBlClicked Then
        MsgBox "double clicked"
        Timer1.Enabled = False
    Else
        MsgBox "clicked"
        Timer1.Enabled = False
    End If
    
    End Sub
    I'm attaching a small sample with

    I hope it helps
    Last edited by HanneSThEGreaT; June 14th, 2010 at 05:42 AM.

  3. #3
    Join Date
    Jul 2009
    Location
    (Presently) Bahrah S.A.
    Posts
    24

    Re: UserControl Events Problem

    Thanks for the warm welcome and the fantastic response. The code worked beautifully. There is a slight delay in the event response but IT WORKS, and the delay is a small trade-off for having the ability to utilize both events. Thanks a Million!!!!

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: UserControl Events Problem

    You're welcome, and good work

    Yeah, the delay is actually caused by the GetDoubleClickTime API. Believe it or not, that is actually the time Windows uses to respond to / determine a Double click event. I'm just glad it worked for you

    Keep posting on this wonderful site

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center