Let’s say you’re trying to set a label’s text. By doing it, you call a function SetText(labelname, “texthere”). What would the SetText ‘header’ be?
I’m trying:
private void SetText(object foo, string bar)
but that doesn’t work
edit: I have this:
private void SetText(Control thing, string text)
{
if (this.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
Invoke(d, new object[] { text });
}
else
{
thing.Text = text;
}
}
But it says something about invalid number of parameters. What do I need to change?
Use Control class instead of Object, as the former defines the base class for controls (components with visual representation) and exposes Text property.
Like this, you don’t need to box/cast the Object. Otherwise you should also specify the type of the object as you could pass a TextBox, a Label and so on…