//点击“添加”按钮,将把在第一文本框中的输入的课程名称添加到左边的列表框中,
//且所添加的课程不能为空,不能重复。
//点击“->”按钮,将把左边列表框中所选课程添加到右边的列表框中,
//同时在左边的列表框中删除掉该课程。点击“<-”按钮,操作同理。
//点击“>>”按钮,将把左边所有的课程都添加到右边的列表框中,同时删除左边列表框中的所有内容。
//点击“<<”按钮,操作同理。
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 简单选课系统
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button8_Click(object sender, EventArgs e)
{
bool exit = false;
if (textBox1.Text == "")
{
MessageBox.Show("新添加课程不能为空!");
textBox1.Clear();
textBox1.Focus();
}
else
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (textBox1.Text == listBox1.Items[i].ToString())
{
MessageBox.Show("不能添加已有课程!");
exit = true;
textBox1.Clear();
textBox1.Focus();
break;
}
}
}
if (exit == false)
{
listBox1.Items.Add(textBox1.Text);
textBox1.Clear();
}
}
private void button4_Click(object sender, EventArgs e)
{
listBox2.Items.Add(listBox1.SelectedItem);
listBox1.Items.Remove(listBox1.SelectedItem);
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < listBox2.Items.Count; i++)
{
listBox1.Items.Add(listBox2.Items[i]);
}
listBox2.Items.Clear();
}
private void button3_Click(object sender, EventArgs e)
{
listBox1.Items.Add(listBox2.SelectedItem);
listBox2.Items.Remove(listBox2.SelectedItem);
}
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
listBox2.Items.Add(listBox1.Items[i]);
}
listBox1.Items.Clear();
}
private void button5_Click(object sender, EventArgs e)
{
for (int i = 0; i < listBox2.Items.Count; i++)
{
MessageBox.Show("您选择了" + listBox2.Items[i].ToString());
}
}
private void button6_Click(object sender, EventArgs e)
{
for (int i = 0; i < listBox2.Items.Count; i++)
{
listBox1.Items.Add(listBox2.Items[i].ToString());
}
listBox2.Items.Clear();
}
private void button7_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
简单选课系统