📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace testListBoxApp
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ListBox lstGoods;
private System.Windows.Forms.Button btnDelOne;
private System.Windows.Forms.Button btnDelAll;
private System.Windows.Forms.TextBox txtGoodsName;
private System.Windows.Forms.Button btnAddOne;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private 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 Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lstGoods = new System.Windows.Forms.ListBox();
this.label1 = new System.Windows.Forms.Label();
this.btnDelOne = new System.Windows.Forms.Button();
this.btnDelAll = new System.Windows.Forms.Button();
this.txtGoodsName = new System.Windows.Forms.TextBox();
this.btnAddOne = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lstGoods
//
this.lstGoods.ItemHeight = 12;
this.lstGoods.Location = new System.Drawing.Point(16, 32);
this.lstGoods.Name = "lstGoods";
this.lstGoods.Size = new System.Drawing.Size(120, 136);
this.lstGoods.TabIndex = 0;
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 8);
this.label1.Name = "label1";
this.label1.TabIndex = 1;
this.label1.Text = "您的购物篮:";
//
// btnDelOne
//
this.btnDelOne.Location = new System.Drawing.Point(200, 40);
this.btnDelOne.Name = "btnDelOne";
this.btnDelOne.TabIndex = 2;
this.btnDelOne.Text = "删除";
this.btnDelOne.Click += new System.EventHandler(this.btnDelOne_Click);
//
// btnDelAll
//
this.btnDelAll.Location = new System.Drawing.Point(200, 80);
this.btnDelAll.Name = "btnDelAll";
this.btnDelAll.TabIndex = 3;
this.btnDelAll.Text = "全部删除";
this.btnDelAll.Click += new System.EventHandler(this.btnDelAll_Click);
//
// txtGoodsName
//
this.txtGoodsName.Location = new System.Drawing.Point(20, 208);
this.txtGoodsName.Name = "txtGoodsName";
this.txtGoodsName.TabIndex = 4;
this.txtGoodsName.Text = "";
//
// btnAddOne
//
this.btnAddOne.Location = new System.Drawing.Point(200, 208);
this.btnAddOne.Name = "btnAddOne";
this.btnAddOne.TabIndex = 5;
this.btnAddOne.Text = "放入篮中";
this.btnAddOne.Click += new System.EventHandler(this.btnAddOne_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 176);
this.label2.Name = "label2";
this.label2.TabIndex = 6;
this.label2.Text = "请输入物品名:";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label2,
this.btnAddOne,
this.txtGoodsName,
this.btnDelAll,
this.btnDelOne,
this.label1,
this.lstGoods});
this.Name = "Form1";
this.Text = "testListBox";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnAddOne_Click(object sender, System.EventArgs e)
{
if (txtGoodsName.Text != "")
{
lstGoods.Items.Add (txtGoodsName.Text );
}
else
{
MessageBox.Show ("Please input the Name!");
}
}
private void btnDelOne_Click(object sender, System.EventArgs e)
{
if (lstGoods.SelectedIndex >= 0){
lstGoods.Items.RemoveAt (lstGoods.SelectedIndex );
}
}
private void btnDelAll_Click(object sender, System.EventArgs e)
{
lstGoods.Items.Clear ();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -