国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#入門之窗體的簡單經(jīng)典用法實例

2019-10-29 21:47:32
字體:
供稿:網(wǎng)友
這篇文章主要介紹了C#入門之窗體的簡單用法,以實例形式分析了注冊頁面程序的實現(xiàn)過程,具有一定的參考借鑒價值,需要的朋友可以參考下
 

本文實例講述了C#窗體的簡單用法。分享給大家供大家參考。具體分析如下:

今天簡單的學(xué)習(xí)了一些控件和事件的運(yùn)用。沒有什么很全面的理論,所以今天就總結(jié)下所寫的程序。一個簡單的注冊頁面程序

注冊頁面程序
 
要求:
 
1. 修改所有的控件Name 屬性

2. 登錄事件   檢測各個控件是否為空,如果是空  彈出注冊失敗    如果成功  則顯示新窗體 并且 新窗體上面顯示    “XXX你好! 歡迎來學(xué)習(xí).Net” 走馬燈形式

密碼輸入三次那么登錄按鈕不可用  3分鐘之后可用

把注冊信息的各個數(shù)據(jù)按照     Rocky|admin|renyanlei@aliyun.com|18301412747|男|足球,籃球,排球”寫入到一個文本文件中

具體代碼如下:

復(fù)制代碼代碼如下:
public partial class Form1 : Form
{
        public Form1()
        {
            InitializeComponent();
        }
         
        int num = 1;   //定義num是為了獲取輸入錯誤的次數(shù)
 
        private void btnregster_Click(object sender, EventArgs e)
        { 
            //如果達(dá)到三次則注冊按鈕將不能使用
            if (num == 3)
            {
                this.btnregster.Enabled = false;
            }
            //定義字符串來接收文本數(shù)據(jù)
            string user = this.txtname.Text.Trim();
            string pwd = this.txtpwd.Text.Trim();  
            string email = this.txtemail.Text.Trim();
            string phone = this.txtphone.Text.Trim();

 

    //判斷用戶名、密碼、郵箱、手機(jī)、性別、愛好是否為空,如果為空,則提示注冊失敗,否則則提示注冊成功,進(jìn)入下一個界面
                if (string.IsNullOrEmpty(user))
                {
                    MessageBox.Show("注冊失敗,未輸入用戶名!");
                    ++num; //計時器的累加
                }
 
                else if (string.IsNullOrEmpty(pwd))
                {
                    MessageBox.Show("注冊失敗,未輸入密碼!");
                    ++num;
                }
 
               else if (txtaginpwd.Text != pwd)
                {
                    MessageBox.Show("注冊失敗,確認(rèn)密碼必須保持一致");
                    ++num;
                }
 
                else if (string.IsNullOrEmpty(email))
                {
                    MessageBox.Show("注冊失敗,未輸入郵箱");
                    ++num;
                }
 
                else if (string.IsNullOrEmpty(phone))
                {
                    MessageBox.Show("注冊失敗,未輸入手機(jī)號");
                    ++num;
                }
 
                else if (cbkbasketball.Checked==false && cbkpaiqiu.Checked==false && cbkscore.Checked==false)//只有在都沒有被選中的情況下才顯示注冊失敗
                {
                    MessageBox.Show("注冊失敗,請選擇愛好!");
                    ++num;
                }
                else if (radman.Checked==false && radwomen.Checked==false  )
                {
                    MessageBox.Show("注冊失敗,請選擇性別"); 
                     ++num;
                }
               else
              {
                   MessageBox.Show("注冊成功");
                   Form2 fm = new Form2(user);//打開Form2的窗體,這里傳入一個參數(shù)user。
                   fm.Show();
                   this.Hide();    //隱藏Form1的窗體  
             }
           //創(chuàng)建一個Regster文本文檔,并寫入注冊信息,且以分隔符(|)隔開
                string gender = string.Empty;
                string like = string.Empty;
              //判斷性別被選中的是哪個,就獲取哪個的文本
                if (radman.Checked == true)
                {
                    gender = radman.Text;
                }
                else
                {
                    gender = radwomen.Text;
                }
              //判斷愛好哪幾個被選中,則獲取選中的文本
                 
                if (this.cbkbasketball.Checked)
                {
                    like += cbkbasketball.Text + ",";
                }
                if (this.cbkpaiqiu.Checked)
                {
                    like += cbkpaiqiu.Text+",";
                   
                }
                if (this.cbkscore.Checked)
                {
                    like += cbkscore.Text+",";
                }
                string[] array = { txtname.Text, txtpwd.Text, txtemail.Text, txtphone.Text, gender,like };//定義一個數(shù)組來接收注冊信息的數(shù)據(jù)
                string strs = string.Empty;
                foreach (var item in array)
               {
                    strs += item;
                    strs = string.Join("|",array);//注冊信息在文本文檔中以分隔符隔開
           }
                File.WriteAllText("Regster.txt", strs);//若只寫文檔名字,則默認(rèn)的路徑是在本項目的bin目錄下。
         }
            private void btnconsole_Click(object sender, EventArgs e)//取消按鈕
      { 
            txtname.Focus();//讓用戶名重新獲取焦點(diǎn)
            txtname.Text = "";
            txtpwd.Text = "";
            txtaginpwd.Text = "";
            txtemail.Text = "";
            txtphone.Text = "";
            radman.Checked = false;
            radwomen.Checked = false;
            cbkbasketball.Checked = false;
            cbkpaiqiu.Checked = false;
            cbkscore.Checked = false;
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
             //輸入三次錯誤后,計時器停止輸入3分鐘后再重新輸入
                this.btnregster.Enabled = true;
        }
 
        private void Form1_Activated(object sender, EventArgs e)
       {
            txtname.Focus();//首先讓用戶名文本框獲得焦點(diǎn)
}

 

希望本文所述對大家的C#程序設(shè)計有所幫助。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 九台市| 榆树市| 湘潭市| 合肥市| 察哈| 留坝县| 景德镇市| 大连市| 固始县| 射阳县| 丰台区| 铁力市| 中西区| 高碑店市| 封丘县| 昭苏县| 固始县| 固阳县| 咸宁市| 阜新市| 西和县| 太白县| 海宁市| 石阡县| 民和| 丹阳市| 卢氏县| 嘉定区| 凤山县| 库尔勒市| 高雄县| 阜新| 铜梁县| 白水县| 扶沟县| 衡山县| 团风县| 虹口区| 香河县| 怀化市| 河曲县|