using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Student{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } class Student { private string stuNumber; private string password; private string age; private string gender; public string StuNumber { get { return stuNumber; } set { stuNumber = value; } } public string Password { get { return password; } set { password = value; } } public string Age { get { return age; } set { age = value; } } public string Gender { get { return gender; } set { gender = value; } } public Student() { } public Student(string stuNumber, string password) { this.StuNumber = StuNumber; this.Password = password; } public Student(string StuNumber, string password, int age, string gender) { //初始化当前对象的四个属性 } public string Show() { string message = string.Format("信息注册成功!学号{0},密码{1},年龄{2},性别{3}。", this.StuNumber, this.Password, this.Age.ToString(), this.Gender); return message; } } private void Form1_Load(object sender, EventArgs e) { cmbGender.Items.Clear(); cmbGender.Items.Add("男"); cmbGender.Items.Add("女"); cmbGender.SelectedIndex = 0; } private void button2_Click(object sender, EventArgs e) { this.Close(); } private void button1_Click(object sender, EventArgs e) { if (int.Parse(this.txtAge.Text) > 100 || int.Parse(this.txtAge.Text) < 0) { this.txtAge.Text = "18"; } if (String.IsNullOrEmpty(this.txtStuNumber.Text) || String.IsNullOrEmpty(this.txtPassword.Text)) { MessageBox.Show("用户名和密码不能为空!"); } else { if (this.txtPassword.Text != this.txtRePassword.Text) { MessageBox.Show("密码和确认密码不一致"); } else { //Student Student = new Student(); Student Student = new Student(this.txtStuNumber.Text, this.txtPassword.Text, int.Parse(this.txtAge.Text), this.cmbGender.Text); MessageBox.Show(Student.Show()); } } } }}
添加回答
举报
0/150
提交
取消