⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 c#精彩编程百例(源代码)
💻 CS
字号:
namespace WinApp_listbox1
{
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.WinForms;
    using System.Data;

    /// <summary>
    ///    Summary description for Form1.
    /// </summary>
    public class Form1 : System.WinForms.Form
    {
        /// <summary>
        ///    Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components;
		private System.WinForms.ListBox listBox1;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
			AddItem("11111111111 Items");
            AddItem("2222222222 Items");
            AddItem("3333333333 Items");
            AddItem("More output…");
        }

        /// <summary>
        ///    Clean up any resources being used.
        /// </summary>
        public override void Dispose()
        {
            base.Dispose();
            components.Dispose();
        }

        /// <summary>
        ///    Required method for Designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container ();
			this.listBox1 = new System.WinForms.ListBox ();
			//@this.TrayHeight = 0;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			listBox1.Location = new System.Drawing.Point (40, 16);
			listBox1.Size = new System.Drawing.Size (208, 232);
			listBox1.TabIndex = 0;
			// New codes that are added by author of the book
			ListItem listitem1=new ListItem("Item 1",new String[]{"Value 1","mit1"});
            ListItem listitem2=new ListItem("Item 2",new String[]{"Value 2","mit2"});
            listBox1.Items.Add(listitem1);
            listBox1.Items.Add(listitem2);
			AddItem("Item one of output");
            AddItem("Item two of output");
            AddItem("More and more items of output");
			this.Text = "Form1";
			this.AutoScaleBaseSize = new System.Drawing.Size (6, 14);
			this.Controls.Add (this.listBox1);
		}
        private int iItems=0;
        public void AddItem(string sItem)
        {
          listBox1.InsertItem(iItems,sItem);
          ++iItems;
        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public static void Main(string[] args) 
        {
            Application.Run(new Form1());
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -