Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# eventhandler. big issue.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Fri Sep 05, 2008 5:32 am    Post subject: C# eventhandler. big issue. Reply with quote

Why can't you delcare a new eventhandler for each new object in a for statement. ?

Code:

Button[] mybutton = new Button[30];

for (int i=0; i<5; i++)
 {
   mybutton[i] = new Button();
   mybutton[i].Click += new EventHandler(???);
 }

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Tue Sep 09, 2008 9:25 am    Post subject: Reply with quote

You can.

Code:

for (int i = 0; i < 5; i++)
{
    //other stuff...
    Buttons[i].Click += new EventHandler(ButtonClickMethod);
}


Or, using Lambda (.NET 3.5)...

Code:

for (int i = 0; i < 5; i++)
{
    Buttons[i].Click += new EventHandler(
        (sender, e) =>
        {
             //do stuff... like
             MessageBox.Show("Button was clicked");
        });
}


A neat little thing you can do:

Code:

for (int i = 0; i < 5; i++)
{
    //do some stuff
    Buttons[i].Tag = i;
    Buttons[i].Click += new EventHandler(
        (sender, e) =>
         {
               MessageBox.Show("Button " + ((int)((Button)sender).Tag).ToString() + " was clicked.");
         });
}

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites