I'm making a windows forms application using C#. I add buttons and other controls programmatically at run time. I'd like to know how to handle those buttons' click events?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
In regards to your comment saying you'd like to know which button was clicked, you could set the .Tag attribute of a button to whatever kind of identifying string you want as it's created and use
seems like this works, while adding a tag with each element of the array
do you know of a better way?
Check out this example How to create 5 buttons and assign individual click events dynamically in C#
Use this code to handle several buttons' click events:
Try the following
If you want to see what button was clicked then you can do the following once you create and assign the buttons. Considering that you create the button IDs manually:
You can also check them from giving a command argument to each button.