簡單學生用戶註冊系統--C#

結果展示

//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);                    
        }
        */
    }    
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章