[netMarketing类库] uiHelper类:辅助跨线程访问控件

命名空间:sharClass.uiHelper

功能:跨线程访问界面上的控件


功能详细说明:

如果在线程中想访问界面上的控件时,可以使用这个uiHelper类,它提供了一些常用控件的可以确保线程安全的访问方式,避免出现跨线程访问控件这样的错误出现。

有关跨线程访问控件的相关话题,童鞋们请参见下面的文章:

C#中Invoke的用法


常用函数列表

public static string GetTextString(Control ctrl)
public static string GetTextString(StatusBarPanel ctrl)
public static void SetTextString(Control ctrl, string text)
public static void SetTextString(Control ctrl, string text, Color backColor)
public static void SetTextString(Control ctrl, string text, bool backColor, bool defaultColor = false)
public static void SetTextString(StatusBarPanel ctrl, string text)
public static void SetTextString(ToolStripStatusLabel ctrl, string text)
public static void SetTextString(RichTextBox ctrl, string text, Color fontColor)
public static void AppendTextString(Control ctrl, string text, bool AndCRLF = true)
public static int GetTextLenght(RichTextBox ctrl)
public static bool GetChecked(CheckBox ctrl)
public static void SetChecked(CheckBox ctrl, bool status)
public static void SetBackColor(Control ctrl, Color backColor)
public static void SetBackColor(ToolStripStatusLabel ctrl, Color backColor)
public static Color GetBackColor(Control ctrl)
public static Color GetBackColor(ToolStripStatusLabel ctrl)
public static void SetForeColor(ToolStripStatusLabel ctrl, Color foreColor)
public static void SetForeColor(Control ctrl, System.Drawing.Color foreColor)
public static Color GetForeColor(Control ctrl)
public static Color GetForeColor(ToolStripStatusLabel ctrl)
public static void SetValue(ProgressBar ctrl, int value)
public static void SetValue(TrackBar ctrl, int value)
public static void SetComboBoxItems(ComboBox ctrl, string[] items)
public static void SetComboBoxItems(ComboBox ctrl, List<string> items)
public static void SetControlEnable(Control ctrl, bool textEnable = true, bool buttonEnable = true)

参考例子:

using sharClass;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace uiHelperTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
        }

        private void button1_Click(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(() =>
            {
                uiHelper.AppendTextString(this.richTextBox1, "AppendTextString"+Environment.NewLine, true);
                uiHelper.SetTextString(this.richTextBox1, "SetTextString" + Environment.NewLine, Color.Red);
                uiHelper.SetTextString(this.richTextBox1, uiHelper.GetTextLenght(this.richTextBox1) + Environment.NewLine, Color.Blue);
                uiHelper.SetTextString(this.textBox1, "hello! lxy");
                uiHelper.SetValue(this.progressBar1, 50);
                uiHelper.SetComboBoxItems(this.comboBox1, new string[] { "红色", "绿色", "蓝色" });
            })).Start();
        }
    }
}

这个类成员都是静态函数,使用简单,就不多做解释了。

目前这个类可以操作的控件以及操作方法都比较少,勇哥以后有时间会不断的增强这个类。

image.png


--------------------- 

作者:hackpig
来源:www.skcircle.com
版权声明:本文为博主原创文章,转载请附上博文链接!

返回类库功能说明目录


本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年3月    »
123
45678910
11121314151617
18192021222324
25262728293031
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864