Generic forms call back?
-
I need to set the text on various form controls(textbox,label,buttons, etc) across threads. Right now, I have one method per control. Below is my SetButtonText method.
private delegate void SetButtonTextCallback(System.Windows.Forms.Button tBox, string text); private void SetButtonText(System.Windows.Forms.Button tBox, string text) { if (tBox.InvokeRequired) { SetButtonBoxCallback d = new SetButtonTextCallback(SetButtonText); this.Invoke(d, new object[] { tBox, text }); } else { tBox.Text = text; } }
Is it possible to have a generic method that I can pass the control and the text. So the call would look like:SetControlText(button1,"foo");
orSetControlText(label3,"bar");
-
I need to set the text on various form controls(textbox,label,buttons, etc) across threads. Right now, I have one method per control. Below is my SetButtonText method.
private delegate void SetButtonTextCallback(System.Windows.Forms.Button tBox, string text); private void SetButtonText(System.Windows.Forms.Button tBox, string text) { if (tBox.InvokeRequired) { SetButtonBoxCallback d = new SetButtonTextCallback(SetButtonText); this.Invoke(d, new object[] { tBox, text }); } else { tBox.Text = text; } }
Is it possible to have a generic method that I can pass the control and the text. So the call would look like:SetControlText(button1,"foo");
orSetControlText(label3,"bar");
Just use System.Windows.Forms.Control instead of System.Windows.Forms.Button. Every Control has a Text property.
- S 50 cups of coffee and you know it's on!
-
Just use System.Windows.Forms.Control instead of System.Windows.Forms.Button. Every Control has a Text property.
- S 50 cups of coffee and you know it's on!