Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. multiple controls firing one event from usercontrol

multiple controls firing one event from usercontrol

Scheduled Pinned Locked Moved Visual Basic
helptutorial
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fu Manchu
    wrote on last edited by
    #1

    hi there, I need to access an unknown number of controls, that may be added by a user to my a usercontrol and each control must fire the same event! i think this is the only way possible that i can do it! for example..imagine a panel and add three buttons to it...then on each mouse enter of each button the same event is triggered, i have tried a number of ways but all failed. please help thanks

    C D 2 Replies Last reply
    0
    • F Fu Manchu

      hi there, I need to access an unknown number of controls, that may be added by a user to my a usercontrol and each control must fire the same event! i think this is the only way possible that i can do it! for example..imagine a panel and add three buttons to it...then on each mouse enter of each button the same event is triggered, i have tried a number of ways but all failed. please help thanks

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Create a single method in your code, and tie the event of each control to that method. Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      • F Fu Manchu

        hi there, I need to access an unknown number of controls, that may be added by a user to my a usercontrol and each control must fire the same event! i think this is the only way possible that i can do it! for example..imagine a panel and add three buttons to it...then on each mouse enter of each button the same event is triggered, i have tried a number of ways but all failed. please help thanks

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Or, if your adding these controls dynamically, look into AddHandler[^]. Don't forget to lookup it's opposite, RemoveHandler. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        F 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Or, if your adding these controls dynamically, look into AddHandler[^]. Don't forget to lookup it's opposite, RemoveHandler. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          F Offline
          F Offline
          Fu Manchu
          wrote on last edited by
          #4

          Hi, i have been quite busy lately due to exams at uni, but i would just like to say thanks for your advice.... The following code is exactly what i needed Add this code and some controls to a form and on each Mouse_Enter of any control the main event is triggered..excellent:-D 'Every control added to the form cause this event to be raised WithEvents MyDummyControl As Button Public Event MyEvent() ' Declare an event. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim mycontrol As Control 'count number of controls For x As Integer = 0 To Me.Controls.Count - 1 'Associate controls mycontrol = Me.Controls.Item(x) ' Associate an event handler with an event. AddHandler mycontrol.MouseEnter, New EventHandler(AddressOf TriggerMyEvent) Next RaiseEvent MyEvent() ' Raise an event. Catch MyError As Exception 'dont do event End Try End Sub Private Sub TriggerMyEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyDummyControl.MouseEnter End Sub Thanks again

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups