zoukankan      html  css  js  c++  java
  • 多线程更新UI 武胜

    private delegate object GetButtonTagDelegate(ref Button b);

    private object GetButtonTag(ref Button b)
            {
                if (InvokeRequired)
                {
                    return Invoke(new GetButtonTagDelegate(GetButtonTag), new object[] {b});
                }

                return b.Tag;
            }

    private delegate int GetComboBoxSelectedIndexDelegate(ref ComboBox cb);

    private int GetComboBoxSelectedIndex(ref ComboBox cb)
            {
                if (InvokeRequired)
                {
                    return (int) Invoke(new GetComboBoxSelectedIndexDelegate(GetComboBoxSelectedIndex), new object[] {cb});
                }

                return cb.SelectedIndex;
            }

    private delegate void ButtonPerformClickDelegate(ref Button b);

    private void ButtonPerformClick(ref Button b)
            {
                if (InvokeRequired)
                {
                    Invoke(new ButtonPerformClickDelegate(ButtonPerformClick), new object[] {b});
                }
                else
                {
                    b.PerformClick();
                }
            }

    private delegate void UpdateCountdownProgressBarDelegate(ref ProgressBar pb, int delay, int elapsed);

    private void UpdateCountdownProgressBar(ref ProgressBar pb, int delay, int elapsed)
            {
                if (InvokeRequired)
                {
                    Invoke(new UpdateCountdownProgressBarDelegate(UpdateCountdownProgressBar), new object[] {pb, delay, elapsed});
                }
                else
                {
                    pb.Minimum = 0;
                    pb.Maximum = delay;

                    if (elapsed < delay)
                    {
                        pb.Value = delay - elapsed;
                    }
                    else
                    {
                        pb.Value = 0;
                    }
                }
            }

    private delegate bool GetCheckBoxCheckedDelegate(ref CheckBox cb);

    private bool GetCheckBoxChecked(ref CheckBox cb)
            {
                if (InvokeRequired)
                {
                    return Convert.ToBoolean(Invoke(new GetCheckBoxCheckedDelegate(GetCheckBoxChecked), new object[] {cb}));
                }

                return cb.Checked;
            }

    private delegate void AddComboBoxItemDelegate(ref ComboBox cb, string item);

    private void AddComboBoxItem(ref ComboBox cb, string item)
            {
                if (InvokeRequired)
                {
                    Invoke(new AddComboBoxItemDelegate(AddComboBoxItem), new object[] {cb, item});
                }
                else
                {
                    cb.Items.Add(item);
                }
            }

  • 相关阅读:
    算法与数据结构基础
    算法与数据结构基础
    算法与数据结构基础
    算法与数据结构基础
    算法与数据结构基础
    算法与数据结构基础
    最佳实践 根据状态操作,这样能避免吃掉异常
    最佳实践 状态设计
    Android HTTPS如何10分钟实现自签名SSL证书
    马桶选购
  • 原文地址:https://www.cnblogs.com/zeroone/p/2681153.html
Copyright © 2011-2022 走看看