zoukankan      html  css  js  c++  java
  • 多列选择框控件checkedListBox演示程序

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;

    namespace ListCheckBox
    {
     /// <summary>
     /// Form1 的摘要说明。
     /// </summary>
     public class Form1 : System.Windows.Forms.Form
        {
      p rivate System.Windows.Forms.Label label1;
      p rivate System.Windows.Forms.Button button1;
      p rivate System.Windows.Forms.Button button2;
            ******* CheckedListBox checkedListBox1;
      /// <summary>
      /// 必需的设计器变量。
      /// </summary>
      p rivate System.ComponentModel.Container components = null;

      public Form1()
      {
       //
       // Windows 窗体设计器支持所必需的
       //
       InitializeComponent();

       //
       // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
       //
      }

      /// <summary>
      /// 清理所有正在使用的资源。
      /// </summary>
      protected override void Dispose( bool disposing )
      {
       if( disposing )
       {
        if (components != null)
        {
         components.Dispose();
        }
       }
       base.Dispose( disposing );
      }

      #region Windows 窗体设计器生成的代码
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      /// </summary>
      p rivate void InitializeComponent()
      {
                this.label1 = new System.Windows.Forms.Label();
                this.button1 = new System.Windows.Forms.Button();
                this.button2 = new System.Windows.Forms.Button();
                this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
                this.SuspendLayout();
                //
                // label1
                //
                this.label1.Location = new System.Drawing.Point(8, 8);
                this.label1.Name = "label1";
                this.label1.Size = new System.Drawing.Size(216, 16);
                this.label1.TabIndex = 1;
                this.label1.Text = "选择西部大开发省、直辖市、自治区";
                //
                // button1
                //
                this.button1.Location = new System.Drawing.Point(48, 128);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(96, 23);
                this.button1.TabIndex = 2;
                this.button1.Text = "显示选择结果";
                this.button1.Click += new System.EventHandler(this.button1_Click);
                //
                // button2
                //
                this.button2.Location = new System.Drawing.Point(184, 128);
                this.button2.Name = "button2";
                this.button2.Size = new System.Drawing.Size(96, 23);
                this.button2.TabIndex = 3;
                this.button2.Text = "关闭应用程序";
                this.button2.Click += new System.EventHandler(this.button2_Click);
                //
                // checkedListBox1
                //
                this.checkedListBox1.CheckOnClick = true;
                this.checkedListBox1.Items.AddRange(new object[] {
                "重庆市",
                "四川省",
                "贵州省",
                "云南省",
                "广西壮族自治区",
                "西自治区",
                "新维吾尔族自治区",
                "内蒙古自治区",
                "宁夏回族自治区",
                "陕西省",
                "甘肃省"});
                this.checkedListBox1.Location = new System.Drawing.Point(8, 24);
                this.checkedListBox1.MultiColumn = true;
                this.checkedListBox1.Name = "checkedListBox1";
                this.checkedListBox1.Size = new System.Drawing.Size(312, 100);
                this.checkedListBox1.TabIndex = 0;
                //
                // Form1
                //
                this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
                this.ClientSize = new System.Drawing.Size(332, 158);
                this.Controls.Add(this.button2);
                this.Controls.Add(this.button1);
                this.Controls.Add(this.label1);
                this.Controls.Add(this.checkedListBox1);
                this.Location = new System.Drawing.Point(1800, 300);
                this.MaximizeBox = false;
                this.Name = "Form1";
                this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                this.Text = "演示多选列表框控件";
                this.ResumeLayout(false);

      }
      #endregion

      /// <summary>
      /// 应用程序的主入口点。
      /// </summary>
      [STAThread]
      static void Main()
      {
       Application.Run(new Form1());
      }

      p rivate void button2_Click(object sender, System.EventArgs e)
      {
       this.Close();
      }

      p rivate void button1_Click(object sender, System.EventArgs e)
      {
       string str="选择结果:";
       for(int i=0;i<this.checkedListBox1.CheckedItems.Count;i++)
       {
        str+=this.checkedListBox1.CheckedItems[i]+"、";
       }
       if(str[str.Length-1]=='、')
       {
        str=str.Substring(0,str.Length-1);
       }
       MessageBox.Show(this,str,"选择结果",MessageBoxButtons.OK,MessageBoxIcon.Information);
      }

     }
    }

  • 相关阅读:
    清除浮动的几种方式
    css 居中问题总结
    Python 数据库Insert语句脚本生成工具(SQL Server)
    Windows安装运行Kafka
    C# 阿里云视频点播--视频转码
    C# 阿里云视频点播
    C# Assembly.LoadFile [A] 无法强制转换为 [B]
    OssFtp 用法
    C# Aspose.Words 用法
    C# 企业微信消息推送对接
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668415.html
Copyright © 2011-2022 走看看