📄 form1.cs
字号:
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(24, 16);
this.button3.TabIndex = 6;
this.button3.Text = ">>";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Font = new System.Drawing.Font("宋体", 7.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button4.Location = new System.Drawing.Point(184, 126);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(24, 16);
this.button4.TabIndex = 7;
this.button4.Text = "<<";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// groupBox5
//
this.groupBox5.Controls.Add(this.radioButton2);
this.groupBox5.Controls.Add(this.radioButton1);
this.groupBox5.Location = new System.Drawing.Point(7, 229);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(136, 72);
this.groupBox5.TabIndex = 4;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "付款方式";
//
// groupBox6
//
this.groupBox6.Controls.Add(this.checkBox3);
this.groupBox6.Controls.Add(this.checkBox2);
this.groupBox6.Controls.Add(this.checkBox1);
this.groupBox6.Location = new System.Drawing.Point(151, 229);
this.groupBox6.Name = "groupBox6";
this.groupBox6.Size = new System.Drawing.Size(144, 88);
this.groupBox6.TabIndex = 5;
this.groupBox6.TabStop = false;
this.groupBox6.Text = "确认方式";
//
// radioButton1
//
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(19, 16);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(85, 24);
this.radioButton1.TabIndex = 0;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "现金";
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(19, 41);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(96, 24);
this.radioButton2.TabIndex = 1;
this.radioButton2.Text = "信用卡";
//
// checkBox1
//
this.checkBox1.Checked = true;
this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox1.Location = new System.Drawing.Point(17, 16);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(96, 24);
this.checkBox1.TabIndex = 0;
this.checkBox1.Text = "电话";
//
// checkBox2
//
this.checkBox2.Location = new System.Drawing.Point(17, 43);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(64, 16);
this.checkBox2.TabIndex = 1;
this.checkBox2.Text = "传真";
//
// checkBox3
//
this.checkBox3.Location = new System.Drawing.Point(17, 64);
this.checkBox3.Name = "checkBox3";
this.checkBox3.Size = new System.Drawing.Size(56, 16);
this.checkBox3.TabIndex = 2;
this.checkBox3.Text = "Email";
//
// button5
//
this.button5.Location = new System.Drawing.Point(327, 237);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(48, 24);
this.button5.TabIndex = 6;
this.button5.Tag = "";
this.button5.Text = "确定";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.Location = new System.Drawing.Point(327, 277);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(48, 24);
this.button6.TabIndex = 7;
this.button6.Text = "取消";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(408, 325);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.groupBox6);
this.Controls.Add(this.groupBox5);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "在线购物";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.groupBox5.ResumeLayout(false);
this.groupBox6.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
switch(comboBox1.SelectedIndex)
{
case 0:
listBox1.Items.Clear();
listBox1.Items.Add("显示器");
listBox1.Items.Add("光驱");
listBox1.Items.Add("打印机");
listBox1.Items.Add("键盘");
break;
case 1:
listBox1.Items.Clear();
listBox1.Items.Add("计算机应用基础");
listBox1.Items.Add("Java程序设计");
listBox1.Items.Add("操作系统");
listBox1.Items.Add("Visual C#.NET");
break;
}
changeButtonState();
}
private void button1_Click(object sender, System.EventArgs e)
{
if(listBox1.SelectedIndex>=0)
{
string s=listBox1.Items[listBox1.SelectedIndex].ToString();
if(listBox2.FindString(s,-1)<0)
{
listBox2.Items.Add(s);
}
else
MessageBox.Show("该商品已经选择!");
}
else
MessageBox.Show("请选择商品");
changeButtonState();
}
private void button2_Click(object sender, System.EventArgs e)
{
if(listBox2.SelectedIndex>=0)
{
listBox2.Items.RemoveAt(listBox2.SelectedIndex);
}
else
MessageBox.Show("请选择商品");
changeButtonState();
}
private void button3_Click(object sender, System.EventArgs e)
{
for(int i=0;i<listBox1.Items.Count;i++)
{
string s=listBox1.Items[i].ToString();
if(listBox2.FindString(s,-1)<0)
{
listBox2.Items.Add(s);
}
}
changeButtonState();
}
private void button4_Click(object sender, System.EventArgs e)
{
listBox2.Items.Clear();
changeButtonState();
}
private void changeButtonState()
{
button4.Enabled=listBox2.Items.Count>0;
button3.Enabled=listBox1.Items.Count>0;
button1.Enabled=listBox1.Items.Count>0&&listBox1.SelectedIndex>=0;
button2.Enabled=listBox2.Items.Count>0&&listBox2.SelectedIndex>=0;
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
changeButtonState();
}
private void listBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
changeButtonState();
}
private void button6_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void button5_Click(object sender, System.EventArgs e)
{
string str;
str="您的姓名:"+textBox1.Text+"\n";
str=str+"您的电话:"+textBox2.Text+"\n";
str=str+"您选择的商品有:"+"\n";
if(listBox2.Items.Count>0)
{
for(int i=0;i<listBox2.Items.Count;i++)
str=str+"\t"+listBox2.Items[i].ToString()+"\n";
}
else
str=str+"无\n";
str=str+"您的付款方式:";
if(radioButton1.Checked==true)
str=str+"现金\n";
else
str=str+"信用卡\n";
str=str+"确认方式有:"+"\n";
if(checkBox1.Checked==true)str=str+"\t电话\n";
if(checkBox2.Checked==true)str=str+"\t传真\n";
if(checkBox3.Checked==true)str=str+"\tEmail\n";
if(DialogResult.Yes==MessageBox.Show(str,"确认对话框",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1))
{
this.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -