C#网络程序设计1-1:委托

图形界面的设计如图:
C#网络程序设计1-1:委托_第1张图片
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 文本抄写员程序
{
    public partial class Form1 : Form
    {
        private delegate void WriteTextBox(char ch);
        private WriteTextBox writeTextBox;
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                textBox1.Clear();
                textBox1.Refresh();
                writeTextBox = new WriteTextBox(WriTextBox1);
                WriTxt(writeTextBox);
                textBox3.Focus();
                textBox3.SelectAll();
            }
            if (checkBox2.Checked == true)
            {
                textBox2.Clear();
                textBox2.Refresh();
                writeTextBox = new WriteTextBox(WriTextBox2);
                WriTxt(writeTextBox);
                textBox3.Focus();
                textBox3.SelectAll();
            }
        }
        private void WriTxt(WriteTextBox wMethod)
        {
            string strdata = textBox3.Text;
            for (int i = 0; i < strdata.Length; i++)
            {
                wMethod(strdata[i]);
                DateTime now = DateTime.Now;
                while (now.AddSeconds(1) > DateTime.Now)
                { }
            }
 
        }
        private void WriTextBox1(char ch)
        {
            textBox1.AppendText(ch + "\r");           
        }
        private void WriTextBox2(char ch)
        {
            textBox2.AppendText(ch + "\r");
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

你可能感兴趣的:(C#网络程序设计)