多线程中访问界面控件的类

using System;
using System.Windows.Forms;

public class UIControl
{
delegate void dg_SetControlVisible(Control c, bool v);
dg_SetControlVisible _dg_SetControlVisible;
void en_dg_SetControlVisible(Control c, bool v)
{
c.Visible = v;
}
public void dSetControlVisible(Control c, bool v)
{
c.Invoke(_dg_SetControlVisible, new object[] { c, v });
}

delegate void dg_SetControlText(Control c, string txt);
dg_SetControlText _dg_SetControlText;
int en_dg_GetControlValue(Control c)
{
    int vl = 0;
    switch (c.GetType().FullName)
    {
        case "System.Windows.Forms.TrackBar":
            vl = ((System.Windows.Forms.TrackBar)c).Value;
            break;
    }
    return vl;
}
public int dGetControlValue(Control c)
{
    return int.Parse(c.Invoke(_dg_GetControlValue, new object[] { c }).ToString());
}

delegate void dg_EnableControl(Control c, bool can);
dg_EnableControl _dg_EnableControl;
void en_dg_EnableControl(Control c, bool can)
{
    c.Enabled = can;
}
public void dSetControlEnable(Control c, bool can)
{
    c.Invoke(_dg_EnableControl, new object[] { c, can });
}


delegate int dg_GetControlValue(Control c);
dg_GetControlValue _dg_GetControlValue;
void en_dg_SetControlText(Control c, string txt)
{
    c.Text = txt;
}
public void dSetControlText(Control c, string txt)
{
    c.Invoke(_dg_SetControlText, new object[] { c, txt });
}



delegate void dg_SetTxtToClipBoard(Form frm, string txt);
dg_SetTxtToClipBoard _dg_SetTxtToClipBoard;
void en_dg_SetTxtToClipBoard(Form frm, string txt)
{
    Clipboard.SetText(txt);
}
public void dSetTxtToClipboard(Form frm, string txt)
{
    frm.Invoke(_dg_SetTxtToClipBoard, new object[] { frm, txt });
}


public UIControl()
{
    _dg_SetTxtToClipBoard = new dg_SetTxtToClipBoard(en_dg_SetTxtToClipBoard);
    _dg_SetControlText = new dg_SetControlText(en_dg_SetControlText);
    _dg_GetControlValue = new dg_GetControlValue(en_dg_GetControlValue);
    _dg_EnableControl = new dg_EnableControl(en_dg_EnableControl);
    _dg_SetControlVisible = new dg_SetControlVisible(en_dg_SetControlVisible);
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

weixin_45504213

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值