Thread: button array event handler

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    button array event handler

    Hi all,

    i'm using an array of button, and i would like to manage the click event of each button in a different way.

    this is part of my code:

    Code:
     array<System::Windows::Forms::Button^>^ pics;

    Code:
    this->pics = (gcnew array<Button^>(101));

    Code:
    for(int i=0;i<101;i++){
    	pics[i] = gcnew Button();
    	pics[i]->Click += gcnew System::EventHandler(this , &GraphForm::pics_Click);
    	Controls->Add(pics[i]);
    }

    Code:
    private: System::Void pics_Click(System::Object^  sender, System::EventArgs^  e) { }


    I tried to send the button array index (i) as parameter to the handler, but this is not allowed, and from "sender" i can not get a usefulk information to understand which button was clicked.

    Thanks a lot for your time,
    Tania

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I'm not really experienced at using managed code from within C++, but is it possible to cast System::Object to a System::Windows::Forms::Button and get to the button's properties like Name or Tag? If so, you could just set the Name or Tag for each button to something unique.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    What are you actually trying to accomplish through this by the way? This seems a convulated way of doing something but I'm not sure what it is you're trying to do as the main objective outside of this.
    He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

    The fool wonders, the wise man asks. - Benjamin Disraeli

    There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  3. event handler for an array of buttons
    By GanglyLamb in forum C# Programming
    Replies: 4
    Last Post: 04-12-2005, 09:52 AM
  4. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  5. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM