Return id or name of the dynamic object that was clicked

2

Hello! I am learning now to create dynamic objects in C #, my question is how to return the Text of the button I clicked for example. Let's say I created 10 numbered dynamic objects (in their case text) from 0 to 9 and I clicked on 3, how will I know that I clicked on 3? What I've done so far:

Itriedtodoitbytakingalookatthe"and" if it had any value stored in it, but apparently not quite as I thought ...

    
asked by anonymous 10.07.2016 / 02:09

2 answers

1

You can share the event between them +/- like this:

private void MeusBotoes(System.Object sender, System.EventArgs e){
      Button botao = default(Button);
      botao = (Button)sender;

      switch (botao.Name){

        case "Button1":
           Interaction.MsgBox("Voce pressionou o botão 1");
        break;

        case "Button2":
           Interaction.MsgBox("Voce pressionou o botão 2");
        break;
           //etc
      }
 }
    
10.07.2016 / 02:23
1

Take the desired property of object sender . In this case is the button (remember to convert to Button).

In the case of buttons, there should be a way to create all of them.

    
10.07.2016 / 02:15