Okay so I have a whole bunch of begininvokes to update my gui. I enable/disable, change the text, and all that beautiful stuff.
This is, unfortunately, how my code looks right now:
- public abstract class update
-
{
-
public delegate void button_Callback(object[] pass);
-
public static void button(object[] pass)
-
{
-
Button button = (Button)pass[0];
-
string command = (string)pass[1];
-
switch (command)
-
{
-
-
case "enable":
-
button.Enabled = (bool)pass[2];
-
break;
-
case "text":
-
button.Text = (string) pass[2];
-
break;
-
default:
-
break;
-
}
-
}
-
}
so when I want to update my gui I type:
- BeginInvoke(new update.button_Callback(update.button),new object[] { new object[] { btn_startspg, "enable", true}});
As you can see, the problem is passing the method name as a string and going through a switch.... a lot of hard-coding
I thought of these solutions but none enthuse me that much:
1) one method per method I want to invoke (doesn't really cut down on the coding)
2) create a child of a button and add a delegate for each signature (this would involve changing all my buttons to the child button)
3) append the button class with some delegates so I can directly invoke them (I could be happy with this but I'm not sure this will work)
There must be a brilliant way to do this.
Any suggestions??