时间呐 等等我~
美好的事物陪伴我们 且显然他们不曾远去~
目录:
数据绑定
- Windows窗体应用程序
- 相应位置添加代码
- 运行结果
>> Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _16040226219
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form2());
}
}
}
>>Form1.cs
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 _16040226219
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = textBox1.Text;//这是需要加的代码段
Form2 fm = new Form2();
fm.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";//需要加的代码段
textBox2.Text = "";
}
private void button4_Click(object sender, EventArgs e)
{
while (listBox1.SelectedItems.Count > 0) //需要加的代码段
{
listBox2.Items.Add(listBox1.SelectedItems[0]);
listBox1.Items.Remove(listBox1.SelectedItems[0]);
}
}
private void button3_Click(object sender, EventArgs e)
{
listBox2.Items.AddRange(listBox1.Items);//需要加的代码段
listBox1.Items.Clear();
}
private void button5_Click(object sender, EventArgs e)
{
while(listBox2.SelectedItems.Count > 0) //需要加的代码段
{
listBox1.Items.Add(listBox2.SelectedItems[0]);
listBox2.Items.Remove(listBox2.SelectedItems[0]);
}
}
private void button6_Click(object sender, EventArgs e)
{
listBox1.Items.AddRange(listBox2.Items);//需要加的代码段
listBox2.Items.Clear();
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
>>Form2.cs
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 _16040226219
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
DataRow row = dataTable1.NewRow();
row[0] = textBox1.Text.ToString();
row[1] = textBox2.Text.ToString();
row[2] = textBox3.Text.ToString();
row[3] = textBox4.Text.ToString();
dataTable1.Rows.Add(row);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = dataTable1.Rows[0]["学号"].ToString();
textBox2.Text = dataTable1.Rows[0]["姓名"].ToString();
textBox3.Text = dataTable1.Rows[0]["性别"].ToString();
textBox4.Text = dataTable1.Rows[0]["年龄"].ToString();
dataTable1.Rows.Clear();
}
private void button3_Click(object sender, EventArgs e)
{
Form1 fm = new Form1();
fm.Show();
this.Hide();
}
}
}
~bye~