由于ToolStripStatuslLble 此类控件继承关系有所问题,不能使用Invoke。找了很久尝试发现可以使用以下方法。
private ToolStripStatuslLble lable;
private void StepLabPrint(string msg)
{
if (lable.GetCurrentParent() != null)
{
if (lable.GetCurrentParent().InvokeRequired)
{
lable.GetCurrentParent().Invoke(new Action(() => StepLab.Text = msg));
}
else
{
lable.Text = msg;
}
}
}
附上以前错误版本的
private Lable lable;
private void LabPrint(string msg)
{
if (lable.InvokeRequired)
{
lable.Invoke(new Action(() => lable.Text = ($"[{DateTime.Now.ToString("yyy-MM-dd HH.mm.ss.fff")}] {msg}\r\n")));
}
else
{
lable.Text = ($"[{DateTime.Now.ToString("yyy-MM-dd HH.mm.ss.fff")}] {msg}\r\n");
}
}
978




被折叠的 条评论
为什么被折叠?



