结果展示
//Form1
//在主窗体中完成主菜单的设计,只有“注册”菜单下的“用户注册”菜单项编写了相应的程序代码,
//点击“用户注册”在主窗体中打开一个有关“学生成绩管理系统”注册协议的文本控件
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;
using 学生成绩管理注册功能.Properties;
namespace 学生成绩管理注册功能
{
public partial class Form1 :Form
{
public Form1()
{
InitializeComponent();
this.IsMdiContainer = true;
}
private void 用户注册ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
//新建一个窗体
form2.MdiParent = this ;
//定义此窗体的父窗体,从而此窗体成为一个MDI窗体
form2.Parent = panel1;
//设置窗体大小
form2.Show();
//把此MDI窗体显示出来
}
}
}
//Form2
//用户点击注册菜单下的用户注册,将在主窗体中打开一个有关“学生成绩管理系统”注册协议的文本控件
//用户点击“我同意”按钮后,将弹出另外一个“用户注册”窗体,
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 学生成绩管理注册功能.Properties
{
public partial class Form2 : Form1
{
public Form2( )
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form3 form3 = new Form3();
//新建一个窗体
form3.ShowDialog();
//把此模式窗体显示出来
}
}
}
//Form3
//用户注册信息包括:学生姓名、性别、密码、确认密码、所在院系、所属专业
//用户注册”窗体中,“密码”与“再次输入密码”文本框中输入的文字要求使用密码屏蔽,
//如果两次输入的密码不一致,将给出提示信息
//如果在“所在院系”中选择不同学院,则在“所属专业”组合框的下拉列表中将显示不同专业
//用户点击“提交”按钮后,将弹出“注册信息确认”窗体,
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 学生成绩管理注册功能.Properties
{
public partial class Form3 : Form
{
public static Form3 form3;
public Form3()
{
InitializeComponent();
form3 = this;
}
private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{
switch (comboBox1.SelectedIndex)
{
case 0:
{
comboBox2.Items.Clear();
comboBox2.Items.Add("计算机科学与技术");
comboBox2.Items.Add("物联网");
comboBox2.Items.Add("电子信息工程");
break;
}
case 1:
{
comboBox2.Items.Clear();
comboBox2.Items.Add("软件工程");
comboBox2.Items.Add("数字媒体");
break;
}
case 2:
{
comboBox2.Items.Clear();
comboBox2.Items.Add("石油工程");
comboBox2.Items.Add("储运工程");
comboBox2.Items.Add("海洋石油工程");
break;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
}
/*
//新建一个formlist集合,供唯一窗口使用
List<Form> formlist = new List<Form>();
public static bool open = false;
//定义一个判断窗体是否弹出的bool类型的变量为false;
public void reRemove(Form4 form40)
{
formlist.Remove(form40);
}
*/
public void button1_Click(object sender, EventArgs e)
{
button1.Enabled = true;
if(textBox1.Text =="")
{
MessageBox.Show("请输入您的姓名!", "提示");
textBox1.Focus();
return;
}
if (radioButton1.Checked == false && radioButton2.Checked == false )
{
MessageBox.Show("请选择您的性别!", "提示");
radioButton1.Focus();
return;
}
if (textBox2.Text.Length < 10)
{
MessageBox.Show("密码过于简单,密码长于应大于十!", "提示");
textBox2.Clear();
textBox3.Clear();
textBox2.Focus();
return;
}
if (textBox2.Text != textBox3.Text)
{
MessageBox.Show("您两次输入的密码不同!", "提示");
textBox2.Clear();
textBox3.Clear();
textBox2.Focus();
return;
}
string sex = "男";
if (radioButton2.Checked)
{
sex = "女";
}
/*
//设置唯一窗口:
Form4 form4 = new Form4();
form4.Name = "form4"; //重新给form2的name赋值,免除发生冲突
if (formlist.Count > 0) //如果集合中有元素
{
foreach (Form form in formlist) //遍历它们
{
if (form.Name == form4.Name) //如果要弹出的窗体对象已经存在
{
open = true; //表示已经弹出
form.Focus(); //焦点定位已经弹出的窗口
}
}
}
if (open) //当前已经有窗口弹出
{
form4.Close(); //把新实例化的窗体对象给释放掉
}
else //如果没有窗口弹出
{
formlist.Add(form4); //将新窗体添加进集合
form4.Show(); //弹出窗体
}
*/
Form4 form4 = new Form4();
form4.textBox1.Text = "姓名:" + textBox1.Text + Environment.NewLine + "性别:" + sex + Environment.NewLine + "密码:" + textBox2.Text + Environment.NewLine + "所属院系:" + comboBox1.Text + Environment.NewLine + "所属专业" + comboBox2.Text + Environment.NewLine;
form4.ShowDialog();
}
}
}
//Form4
//放置一个文本框控件,在该控件中需要将用户在“用户注册”窗体中录入的信息进行展示
//点击“注册信息确认”按钮后,将弹出一消息框,注:在该消息框中,有“是”和“否”两个按钮,
//当用户点击“是”按钮时,整个应用程序退出;
//当用户点击“否”按钮时,将“注册信息确认”窗体退出,重返到“用户注册”窗体。
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 学生成绩管理注册功能.Properties
{
public partial class Form4 : Form
{
public Form4( )
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确认退出吗?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
Application.Exit();
}
else
{
this.Close();
}
}
/*
private void Form4_FormClosing(object sender, FormClosingEventArgs e)
{
Form3 .form3 .reRemove(this);
}
*/
}
}