c#桌面程序

 private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileDialog = new OpenFileDialog();
            fileDialog.Multiselect = true;
            fileDialog.Title = "请选择文件";
            fileDialog.Filter = "所有文件(*.*)|*.txt*";
           
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                string file = fileDialog.FileName;

                MessageBox.Show("已选择文件:" + file, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox1.Text = file;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(((Button)sender).Name + " was clicked.");
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                //...
            }
        }
        string chattextbox;
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            chattextbox = textBox1.Text;
            
        }

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show(chattextbox);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            toGetBat("hhh");
        }
        private void toGetBat(string s)
        {
            Process process = new Process();
            string filePath= "E:\workspace\bat\testcsharp.bat";
            ProcessStartInfo psi = new ProcessStartInfo(filePath, "haha1 haha2 haha3");
            psi.UseShellExecute = false;
            //  process.StartInfo.FileName = "E:\workspace\bat\testcsharp.bat";
            // process.StartInfo.UseShellExecute = true;

            //这里相当于传参数 
            // process.StartInfo.Arguments = "cl";
            process.StartInfo = psi;
            process.Start();

            //测试同步执行 
           // process.WaitForExit();

            //测试第二次运行 
           // process.StartInfo.Arguments = "@echo hahaha";
          //  process.Start();
           // process.WaitForExit();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            textBox2.AllowDrop = true;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            //checkBox1.
        }
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace WindowDemo
{
    public partial class MyForm : Form
    {
        private string fileName;
        private string[] lines;
        public MyForm()
        {
            InitializeComponent();
        }

        private void MyForm_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Add("aa");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("hhhh");
            System.Console.WriteLine("hhh");
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            string text = System.IO.File.ReadAllText(@"E:workspaceTXTa.txt");
           lines = System.IO.File.ReadAllLines(@"E:workspaceTXTa.txt");
            System.Console.WriteLine(text);
            foreach(string s in lines)
            {
                System.Console.WriteLine(s);
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox1.Items.Add("aa");
            foreach (string s in lines)
            {
                comboBox1.Items.Add(s);
            }

        }
       
    }
}

提示文本:
label:
复选框集合:richTextBox1_TextChanged
添加复选框,对复选框监听
CheckedListBox:复选框列表
 _list.SelectedIndexChanged += list_SelectedIndexChanged;委托
 
  private CheckedListBox _list;
  
  private void adListView_CheckBox()
        {
            _list = new CheckedListBox();
            _list.CheckOnClick = true;

            _list.Width = this.Width-100;
            _list.Height = 100;
            _list.ColumnWidth = 120;
            _list.MultiColumn = true;
           
            for (int i = 0; i < _data.ChannelNames.Count; i++)
            {
                _list.Items.Add(_data.ChannelNames[i]);
            }
            _list.SelectedIndexChanged += list_SelectedIndexChanged;
            _list.HorizontalScrollbar = false;
            _list.Parent = this;
            _list.Location = new Point(50, 240);
        }
		
	 private void list_SelectedIndexChanged(object val, EventArgs info)
        {
            CheckedListBox _box = val as CheckedListBox;
            seleString.Clear();
            for (int i = 0; i < _box.Items.Count; i++)
            {
                if (_box.GetItemChecked(i))
                {
                    seleString.Add(_data.ChannelNames[i]);
                }
                else
                {
                    _box.SetItemChecked(i, false);
                }
            }
            System.Console.Out.WriteLine(seleString.Count());
            _data.SelectChannels(seleString);

        }

在design.cs中修改按钮事件监听
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);

单开一个类作为变量存储

提示文本:
label:
复选框集合:richTextBox1_TextChanged
添加复选框,对复选框监听
CheckedListBox:复选框列表
_list.SelectedIndexChanged += list_SelectedIndexChanged;委托

private CheckedListBox _list;

private void adListView_CheckBox()
{
_list = new CheckedListBox();
_list.CheckOnClick = true;

        _list.Width = this.Width-100;
        _list.Height = 100;
        _list.ColumnWidth = 120;
        _list.MultiColumn = true;
       
        for (int i = 0; i < _data.ChannelNames.Count; i++)
        {
            _list.Items.Add(_data.ChannelNames[i]);
        }
        _list.SelectedIndexChanged += list_SelectedIndexChanged;
        _list.HorizontalScrollbar = false;
        _list.Parent = this;
        _list.Location = new Point(50, 240);
    }
	
 private void list_SelectedIndexChanged(object val, EventArgs info)
    {
        CheckedListBox _box = val as CheckedListBox;
        seleString.Clear();
        for (int i = 0; i < _box.Items.Count; i++)
        {
            if (_box.GetItemChecked(i))
            {
                seleString.Add(_data.ChannelNames[i]);
            }
            else
            {
                _box.SetItemChecked(i, false);
            }
        }
        System.Console.Out.WriteLine(seleString.Count());
        _data.SelectChannels(seleString);

    }
原文地址:https://www.cnblogs.com/mada0/p/5146863.html