zoukankan      html  css  js  c++  java
  • 图2 不带EventArgs的委托演示

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Threading;

    namespace hackpig
    {
        public class myFormControl : Form
        {
            public delegate void addListItem(String str1);
            public addListItem myDelegate;
            p rivate Button myButton;
            p rivate ListBox myListBox;
            p rivate Thread myThread;

            public myFormControl()
            {
                myButton = new Button();
                myListBox = new ListBox();
                myButton.Location = new Point(72, 160);
                myButton.Size = new Size(152, 32);
                myButton.Text = "增加项目到listbox";
                myButton.TabIndex = 1;
                myButton.Click+=new EventHandler(myButton_Click);
                //myButton.Invoke();
                myListBox.Location = new Point(48, 32);
                myListBox.Size = new Size(200, 95);
                myListBox.Name = "list1";
                myListBox.TabIndex = 2;

                ClientSize = new Size(292, 273);
                Controls.AddRange(new Control[] { myButton, myListBox });
                Text = "控件的Invoke的演示程序";
                myDelegate = new addListItem(addListItemMethod);


            }

            public void addListItemMethod(String str1)
            {
                myListBox.Items.Add(str1);
            }

            p rivate void myButton_Click(object sender, EventArgs e)
            {
                myThread = new Thread(new ThreadStart(threadFunction));
                myThread.Start();

            }

            p rivate void threadFunction()
            {
                myThreadClass myThreadClassObject = new myThreadClass(this);
                myThreadClassObject.run();
            }

            static void Main()
            {
                myFormControl myForm = new myFormControl();
                myForm.ShowDialog();
            }
        }

        //=================================
        public class myThreadClass
        {
            myFormControl myFormControl_1;
            public myThreadClass(myFormControl myform)
            {
                myFormControl_1 = myform;
            }

            public void run()
            {
                String str1 = "猪悟能";
                myFormControl_1.Invoke(myFormControl_1.myDelegate,new object[]{str1});
            }
        }

    }

     本例源代码下载

  • 相关阅读:
    解决方案下显示的网站名称被追加编号的问题解决方法
    sql server 2008 报表服务器(sql server 2008 report service)中如何固定行或者列
    如何通过参数来切换图表和数据
    饼图中如何将一定比例的小切片收集在一起
    饼图图例中显示百分比值
    如何根据条件隐藏列
    饼图上如何显示百分比值
    负载均衡
    在UTF8页中接收和使用以GB2312方式进行URL编码的中文数据
    ASP 格式化显示时间为几个月,几天前,几小时前,几分钟前,或几秒前
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668474.html
Copyright © 2011-2022 走看看