在我的应用程序中我使用backgroundWorker,在一些TextBox中设置文本,我首先需要调用TextBox.
首先我使用:
if (someTextBox.InvokeRequired)
{
someTextBox.Invoke((MethodInvoker)delegate
{
someTextBox.Text = "some_text";
});
}
else
{
someTextBox.Text = "some_text";
}
Run Code Online (Sandbox Code Playgroud)
这个方法对我很好,但因为我有多个TextBox-es我写道:
private void invComp(TextBox txtBox, String str)
{
if (txtBox.InvokeRequired)
{
txtBox.Invoke((MethodInvoker)delegate
{
txtBox.Text = str;
});
}
else
{
txtBox.Text = str;
}
}
Run Code Online (Sandbox Code Playgroud)
最好以这种方式调用它?(invComp(someTextBox,"some_text");或者我可能有第三种,更好的方式?
我调用了一些按钮,我想在按钮上写这样的东西,如果这样可以吗?
TNX