Click here to Skip to main content
15,909,498 members
Home / Discussions / C#
   

C#

 
AnswerRe: browse through elemnts of container / subscribe event Pin
Hessam Jalali21-Aug-07 9:03
Hessam Jalali21-Aug-07 9:03 
you can use recursive method (as deep first search or stack search)

it would be somewhat like this
void AssociateClick(Control starterControl)
{
    if(starterControl==null)return;

    foreach(Control c in starterControl.Controls)
    {
        if(c is Button)
        c.Click+=new EventHandler(c_Click);
        AssociateClick(c);
    }
}

void c_Click(object sender, EventArgs e)
{
    //just for testing
    MessageBox.Show((sender as Button).Name);
}


if you pass the form as starter it would iterate in all controls and if iterated control is a button the c_Click method would be associated to that

and of course it can be implemented with other methods like Breadth search (with Q) but maybe recursive is the easiest way in this case

hope the post would be useful

good luck Smile | :)
GeneralRe: browse through elemnts of container / subscribe event Pin
ezazazel21-Aug-07 21:43
ezazazel21-Aug-07 21:43 
QuestionWriting byte stream Pin
gauthee21-Aug-07 5:38
gauthee21-Aug-07 5:38 
AnswerRe: Writing byte stream Pin
Luc Pattyn21-Aug-07 5:48
sitebuilderLuc Pattyn21-Aug-07 5:48 
QuestionThread Synchronization Pin
topksharma198221-Aug-07 4:14
topksharma198221-Aug-07 4:14 
AnswerRe: Thread Synchronization Pin
Luc Pattyn21-Aug-07 5:27
sitebuilderLuc Pattyn21-Aug-07 5:27 
QuestionApplication terminates when window gets closed Pin
MarioMARTIN21-Aug-07 3:59
MarioMARTIN21-Aug-07 3:59 
AnswerRe: Application terminates when window gets closed Pin
MarioMARTIN21-Aug-07 5:07
MarioMARTIN21-Aug-07 5:07 
GeneralRe: Application terminates when window gets closed Pin
Not Active21-Aug-07 5:44
mentorNot Active21-Aug-07 5:44 
GeneralRe: Application terminates when window gets closed Pin
MarioMARTIN21-Aug-07 5:47
MarioMARTIN21-Aug-07 5:47 
GeneralRe: Application terminates when window gets closed Pin
Not Active21-Aug-07 11:03
mentorNot Active21-Aug-07 11:03 
GeneralRe: Application terminates when window gets closed Pin
MarioMARTIN21-Aug-07 19:30
MarioMARTIN21-Aug-07 19:30 
GeneralRe: Application terminates when window gets closed Pin
Not Active22-Aug-07 0:21
mentorNot Active22-Aug-07 0:21 
AnswerRe: Application terminates when window gets closed Pin
Luc Pattyn21-Aug-07 5:52
sitebuilderLuc Pattyn21-Aug-07 5:52 
GeneralRe: Application terminates when window gets closed Pin
MarioMARTIN21-Aug-07 6:00
MarioMARTIN21-Aug-07 6:00 
GeneralRe: Application terminates when window gets closed Pin
Luc Pattyn21-Aug-07 6:23
sitebuilderLuc Pattyn21-Aug-07 6:23 
AnswerRe: Application terminates when window gets closed Pin
MarioMARTIN21-Aug-07 6:19
MarioMARTIN21-Aug-07 6:19 
GeneralRe: Application terminates when window gets closed Pin
Martin#21-Aug-07 8:17
Martin#21-Aug-07 8:17 
GeneralRe: Application terminates when window gets closed Pin
MarioMARTIN21-Aug-07 19:21
MarioMARTIN21-Aug-07 19:21 
GeneralRe: Application terminates when window gets closed Pin
Martin#21-Aug-07 21:17
Martin#21-Aug-07 21:17 
AnswerRe: Application terminates when window gets closed Pin
MarioMARTIN21-Aug-07 19:35
MarioMARTIN21-Aug-07 19:35 
Questionc# Pin
lankaudaranga21-Aug-07 2:40
lankaudaranga21-Aug-07 2:40 
AnswerRe: c# Pin
Justin Perez21-Aug-07 2:43
Justin Perez21-Aug-07 2:43 
GeneralRe: c# Pin
leckey21-Aug-07 3:54
leckey21-Aug-07 3:54 
GeneralRe: c# Pin
Justin Perez21-Aug-07 3:57
Justin Perez21-Aug-07 3:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.