讲代码补充完整using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace one { public partial class Form1 : Form { private Classes mycla = new Classes(); public Form1() { InitializeComponent(); } private void List() { // Student s; textBox3.Text = ""; for (int i = 1; i <=mycla.Count; i++) { //编写代码 //.... // textBox3.Text += s.code + "\t"+s.Name+"\r\n"; } } private void button1_Click(object sender, EventArgs e) { //编写程序 List();//显示学生信息 } private void button2_Click(object sender, EventArgs e) { //编写代码 } } }
时间: 2024-02-10 22:19:13 浏览: 60
以上是一个Windows Forms应用程序的部分代码,包含一个窗体类Form1和一个Classes类对象mycla。下面是将其使用的代码补充完整:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace one
{
public partial class Form1 : Form
{
private Classes mycla = new Classes();
public Form1()
{
InitializeComponent();
}
private void List()
{
textBox3.Text = "";
for (int i = 1; i <= mycla.Count; i++)
{
Student s = mycla.GetStudent(i);
textBox3.Text += s.code + "\t" + s.Name + "\r\n";
}
}
private void button1_Click(object sender, EventArgs e)
{
List();
}
private void button2_Click(object sender, EventArgs e)
{
string code = textBox1.Text;
string name = textBox2.Text;
Student s = new Student(code, name);
mycla.AddStudent(s);
textBox1.Text = "";
textBox2.Text = "";
List();
}
}
}
在List方法中,我们使用for循环遍历mycla对象中所有的学生信息,并且将每个学生的学号和姓名信息打印在textBox3中。
在button2_Click方法中,我们通过textBox1和textBox2获取用户输入的学号和姓名信息,并且创建一个新的学生对象s,将其添加到mycla对象中。最后清空textBox1和textBox2,并且调用List方法刷新显示。
阅读全文