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. C#
  4. How to make an EventHandler for array of buttons

How to make an EventHandler for array of buttons

Scheduled Pinned Locked Moved C#
csharpdata-structureshelptutorial
2 Posts 2 Posters 0 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.
  • T Offline
    T Offline
    t_nedelchev
    wrote on last edited by
    #1

    Hello everybody. I have a problem.I'm working with VS2005 and my project is a C# windows application. I define an array of buttons but I don't know how to make EventHandler for this array; Thanks for all. t_nedelchev

    U 1 Reply Last reply
    0
    • T t_nedelchev

      Hello everybody. I have a problem.I'm working with VS2005 and my project is a C# windows application. I define an array of buttons but I don't know how to make EventHandler for this array; Thanks for all. t_nedelchev

      U Offline
      U Offline
      Utkarshraj Atmaram
      wrote on last edited by
      #2

      for (i=0; i < ...) {
      btnArr[i].Click += new System.EventHandler(NameOfYourClickHandler);
      btnArr[i].Tag = i; // this is needed so that you can identify which
      // button was clicked
      }

      Then declare a function called NameOfYourClickHandler:

      public void NameOfYourClickHandler(object sender, System.EventArgs e) {
      // do something
      MessageBox.Show(((System.Windows.Button)sender).Tag.ToString());
      }

      Ut

      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