Results 1 to 8 of 8

Thread: Handling two events

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Handling two events

    I'm trying to get my Sub, named "Whatever" to handle the events raised by two separate controls: a button, and a toolbar. The toolbar is a custom one, and as a result, the signatures of the two are not the same.

    Is there anything I can do so that "Whatever" can somehow handle both their events

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Yup, just stick a comma at the end:

    Handles Button1.Click, Button2.Click


    All signatures are the same using:

    ByVal sender As System.Object, ByVal e As System.EventArgs

    They just impliment different version of them, and you can check which control is was, by looking at the "sender" value.

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Unfortunately, the signature here isn't the same as it is for the button click.

    Let me show you:

    VB Code:
    1. Public Sub Whatever(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles UltraToolbarsManager1.ToolClick
    2.         If TypeOf e.Tool Is Infragistics.Win.UltraWinToolbars.PopupColorPickerTool Then
    3.             Me.ForeColor = color1.SelectedColor
    4.         End If
    5.  
    6.     End Sub

    Here is the Sub I've created to handle the toolbar clicks. Now I need Button1 to actually call this with the proper 'arguments'

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. 'I have no idea what to put here
    3.  
    4.     End Sub

    Now you see what's wrong? I'm still new to VB.NET, so please explain to me if I'm going about things the wrong way.


  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    A blind shot .
    VB Code:
    1. 'In Button1_Click  
    2.  
    3. Whatever(sender, DirectCast(e, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs))

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,


    Is it too easy to suggest the code for button1 as:

    ToolBarButton.PerformClick


    ??
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  6. #6
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    VB Code:
    1. ByVal e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs

    The class ToolClickEventArgs is an implementation class of EventArgs so any sub declared as:-

    VB Code:
    1. Private Sub CombinedEventHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
    2.  
    3.    
    4.  
    5.     End Sub

    Will work.

  7. #7
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Originally posted by Merrion
    The class ToolClickEventArgs is an implementation class of EventArgs so any sub declared as:-
    There is only 1 base event signature, and everything (as stated) is based on those, and you can just cast it to the one you need. But saying that, if you are trying to use the same event to handle two different controls, and you actually need specific info from the argument (well one of them), then are you sure you dont need two different events that call another procedure with the corrected arguments ?

  8. #8
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by mendhak
    Unfortunately, the signature here isn't the same as it is for the button click.

    Let me show you:

    VB Code:
    1. Public Sub Whatever(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinToolbars.ToolClickEventArgs) Handles UltraToolbarsManager1.ToolClick
    2.         If TypeOf e.Tool Is Infragistics.Win.UltraWinToolbars.PopupColorPickerTool Then
    3.             Me.ForeColor = color1.SelectedColor
    4.         End If
    5.  
    6.     End Sub

    Here is the Sub I've created to handle the toolbar clicks. Now I need Button1 to actually call this with the proper 'arguments'

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. 'I have no idea what to put here
    3.  
    4.     End Sub

    Now you see what's wrong? I'm still new to VB.NET, so please explain to me if I'm going about things the wrong way.

    you dumb frog! hehe jk
    first, rename UltraWinToolbars to UWinToolbars (sounds better). so you'd have Infragistics.Win.UWinToolbars (+ you can rename Infragistics to Infrogistics)

    second, do what merrion said
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

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



Click Here to Expand Forum to Full Width