I created a program to over UltraVNC to easier manage some computers since their aren’t many (<25) each PC has it’s own button and according to a toggle toolstrip I can view or manage that computer among other things.
I already have a version functioning just fine but I want to add some features refine my old code. All 15 button that I currently use to represent computer call the same function. I was wondering is there a better way to that this:
private void PC1_Click(object sender, EventArgs e)
{
Viewer("01", activeButton);
}
private void PC2_Click(object sender, EventArgs e)
{
Viewer("02", activeButton);
}
private void PC3_Click(object sender, EventArgs e)
{
Viewer("03", activeButton);
}
private void PC4_Click(object sender, EventArgs e)
{
Viewer("04", activeButton);
}
private void PC5_Click(object sender, EventArgs e)
{
Viewer("05", activeButton);
}
I have been searching for awhile but can’t find a thing. I just can’t think what it is I need. The buttons are already created but I can’t find a way to add this function call to it, I only seem to find how to create a button on startup.
You can simply subscribe the same method as each click handler.
For example, in the Designer, you can go to the properties for a button, select the events tab, click on the Click button drop-down and select an existing method (e.g. PC1_Click for the PC2 button). You don’t have to create a new handler (e.g. double-clicking the button).