form1.cs
来自「Sams Teach Yourself C# Web Programming i」· CS 代码 · 共 182 行
CS
182 行
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Lists
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class fclsLists : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox lstPinkFloydAlbums;
private System.Windows.Forms.Button btnAddItem;
private System.Windows.Forms.Button btnRemoveItem;
private System.Windows.Forms.Button btnClearList;
private System.Windows.Forms.Button btnShowItem;
private System.Windows.Forms.ComboBox cboColors;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public fclsLists()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lstPinkFloydAlbums = new System.Windows.Forms.ListBox();
this.btnAddItem = new System.Windows.Forms.Button();
this.btnRemoveItem = new System.Windows.Forms.Button();
this.btnClearList = new System.Windows.Forms.Button();
this.btnShowItem = new System.Windows.Forms.Button();
this.cboColors = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// lstPinkFloydAlbums
//
this.lstPinkFloydAlbums.Items.AddRange(new object[] {
"Atom Heart Mother",
"Saucer Fill of Secrets",
"Wish You Were Here",
"Animals",
"Echoes",
"Piper at the Gates of Dawn"});
this.lstPinkFloydAlbums.Location = new System.Drawing.Point(73, 32);
this.lstPinkFloydAlbums.Name = "lstPinkFloydAlbums";
this.lstPinkFloydAlbums.Size = new System.Drawing.Size(160, 121);
this.lstPinkFloydAlbums.TabIndex = 0;
//
// btnAddItem
//
this.btnAddItem.Location = new System.Drawing.Point(104, 160);
this.btnAddItem.Name = "btnAddItem";
this.btnAddItem.Size = new System.Drawing.Size(96, 23);
this.btnAddItem.TabIndex = 1;
this.btnAddItem.Text = "Add an Item";
this.btnAddItem.Click += new System.EventHandler(this.btnAddItem_Click);
//
// btnRemoveItem
//
this.btnRemoveItem.Location = new System.Drawing.Point(104, 192);
this.btnRemoveItem.Name = "btnRemoveItem";
this.btnRemoveItem.Size = new System.Drawing.Size(96, 23);
this.btnRemoveItem.TabIndex = 2;
this.btnRemoveItem.Text = "Remove an Item";
this.btnRemoveItem.Click += new System.EventHandler(this.btnRemoveItem_Click);
//
// btnClearList
//
this.btnClearList.Location = new System.Drawing.Point(104, 224);
this.btnClearList.Name = "btnClearList";
this.btnClearList.Size = new System.Drawing.Size(96, 23);
this.btnClearList.TabIndex = 3;
this.btnClearList.Text = "Clear List";
this.btnClearList.Click += new System.EventHandler(this.btnClearList_Click);
//
// btnShowItem
//
this.btnShowItem.Location = new System.Drawing.Point(104, 256);
this.btnShowItem.Name = "btnShowItem";
this.btnShowItem.Size = new System.Drawing.Size(96, 23);
this.btnShowItem.TabIndex = 4;
this.btnShowItem.Text = "Show Selected";
this.btnShowItem.Click += new System.EventHandler(this.btnShowItem_Click);
//
// cboColors
//
this.cboColors.Items.AddRange(new object[] {
"Black",
"Blue",
"Gold",
"Green",
"Red",
"Yellow"});
this.cboColors.Location = new System.Drawing.Point(72, 8);
this.cboColors.Name = "cboColors";
this.cboColors.Size = new System.Drawing.Size(160, 21);
this.cboColors.TabIndex = 5;
//
// fclsLists
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 286);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.cboColors,
this.btnShowItem,
this.btnClearList,
this.btnRemoveItem,
this.btnAddItem,
this.lstPinkFloydAlbums});
this.Name = "fclsLists";
this.Text = "Lists Example";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new fclsLists());
}
private void btnAddItem_Click(object sender, System.EventArgs e)
{
lstPinkFloydAlbums.Items.Add("Dark Side of the Moon");
}
private void btnRemoveItem_Click(object sender, System.EventArgs e)
{
lstPinkFloydAlbums.Items.Remove("Dark Side of the Moon");
}
private void btnClearList_Click(object sender, System.EventArgs e)
{
lstPinkFloydAlbums.Items.Clear();
}
private void btnShowItem_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Debug.WriteLine(lstPinkFloydAlbums.SelectedItem);
System.Diagnostics.Debug.WriteLine(lstPinkFloydAlbums.SelectedIndex);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?