zoukankan      html  css  js  c++  java
  • 多线程UI

    遇到过要在工作线程中去更新UI以让用户知道进度,而在多线程中直接调用UI控件操作是错误的做法。

    最后解决方法是将操作UI的代码封装,通过Invoke / BeginInvoke 去委托调用。

    private void UpdatelblText(string str)
            {
                if (lblText.InvokeRequired)
                {
                    lblText.Invoke(new Action<string>(UpdatelblText), str);
                }
                else
                {
                    lblText.Text = str;
                }
            }
    

     或

    private void ChangeColor(int row, string ShowColor, string InvoiceStatus, string PrintStatus)
            {
                if (dataGridView1.InvokeRequired)
                {
                    this.Invoke(new Action<int, string, string, string>(ChangeColor), new object[] { row, ShowColor, InvoiceStatus, PrintStatus });
                }
                else
                {
                    if (ShowColor == "Green")
                    {
                        dataGridView1.Rows[row].DefaultCellStyle.BackColor = Color.Green;
                        dataGridView1.Rows[row].DefaultCellStyle.ForeColor = Color.White;
                    }
                    else if (ShowColor == "Yellow")
                    {
                        dataGridView1.Rows[row].DefaultCellStyle.BackColor = Color.Yellow;
                        dataGridView1.Rows[row].DefaultCellStyle.ForeColor = Color.Black;
                    }
                    else if (ShowColor == "Red")
                    {
                        dataGridView1.Rows[row].DefaultCellStyle.BackColor = Color.Red;
                        dataGridView1.Rows[row].DefaultCellStyle.ForeColor = Color.White;
                    }
                    dataGridView1.Rows[row].Cells[2].Value = InvoiceStatus;//开票状态
                    dataGridView1.Rows[row].Cells[3].Value = PrintStatus;//打印状态
                }
    
            }
    
  • 相关阅读:
    Sum Root to Leaf Numbers深度优先计算路径和
    Path Sum II深度优先找路径
    动态和静态链接库
    C/C++变量
    搜索
    基本格式
    随机数生成函数
    珍惜生命,我用Python 。今天开始学习Python
    在windows里hexo 博客创建步骤
    作为一个程序员,什么是脚本。必须要理解
  • 原文地址:https://www.cnblogs.com/zeroone/p/9021652.html
Copyright © 2011-2022 走看看