亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#入門(mén)之窗體的簡(jiǎn)單用法實(shí)例

 更新時(shí)間:2014年12月19日 09:00:52   投稿:shichen2014  
這篇文章主要介紹了C#入門(mén)之窗體的簡(jiǎn)單用法,以實(shí)例形式分析了注冊(cè)頁(yè)面程序的實(shí)現(xiàn)過(guò)程,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

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

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

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

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

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

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

具體代碼如下:

復(fù)制代碼 代碼如下:
public partial class Form1 : Form
{
        public Form1()
        {
            InitializeComponent();
        }
        
        int num = 1;   //定義num是為了獲取輸入錯(cuò)誤的次數(shù)
 
        private void btnregster_Click(object sender, EventArgs e)
        {
            //如果達(dá)到三次則注冊(cè)按鈕將不能使用
            if (num == 3)
            {
                this.btnregster.Enabled = false;
            }
            //定義字符串來(lái)接收文本數(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ī)、性別、愛(ài)好是否為空,如果為空,則提示注冊(cè)失敗,否則則提示注冊(cè)成功,進(jìn)入下一個(gè)界面
                if (string.IsNullOrEmpty(user))
                {
                    MessageBox.Show("注冊(cè)失敗,未輸入用戶名!");
                    ++num; //計(jì)時(shí)器的累加
                }
 
                else if (string.IsNullOrEmpty(pwd))
                {
                    MessageBox.Show("注冊(cè)失敗,未輸入密碼!");
                    ++num;
                }
 
               else if (txtaginpwd.Text != pwd)
                {
                    MessageBox.Show("注冊(cè)失敗,確認(rèn)密碼必須保持一致");
                    ++num;
                }
 
                else if (string.IsNullOrEmpty(email))
                {
                    MessageBox.Show("注冊(cè)失敗,未輸入郵箱");
                    ++num;
                }
 
                else if (string.IsNullOrEmpty(phone))
                {
                    MessageBox.Show("注冊(cè)失敗,未輸入手機(jī)號(hào)");
                    ++num;
                }
 
                else if (cbkbasketball.Checked==false && cbkpaiqiu.Checked==false && cbkscore.Checked==false)//只有在都沒(méi)有被選中的情況下才顯示注冊(cè)失敗
                {
                    MessageBox.Show("注冊(cè)失敗,請(qǐng)選擇愛(ài)好!");
                    ++num;
                }
                else if (radman.Checked==false && radwomen.Checked==false  )
                {
                    MessageBox.Show("注冊(cè)失敗,請(qǐng)選擇性別");
                     ++num;
                }
               else
              {
                   MessageBox.Show("注冊(cè)成功");
                   Form2 fm = new Form2(user);//打開(kāi)Form2的窗體,這里傳入一個(gè)參數(shù)user。
                   fm.Show();
                   this.Hide();    //隱藏Form1的窗體 
             }
           //創(chuàng)建一個(gè)Regster文本文檔,并寫(xiě)入注冊(cè)信息,且以分隔符(|)隔開(kāi)
                string gender = string.Empty;
                string like = string.Empty;
              //判斷性別被選中的是哪個(gè),就獲取哪個(gè)的文本
                if (radman.Checked == true)
                {
                    gender = radman.Text;
                }
                else
                {
                    gender = radwomen.Text;
                }
              //判斷愛(ài)好哪幾個(gè)被選中,則獲取選中的文本
                
                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 };//定義一個(gè)數(shù)組來(lái)接收注冊(cè)信息的數(shù)據(jù)
                string strs = string.Empty;
                foreach (var item in array)
               {
                    strs += item;
                    strs = string.Join("|",array);//注冊(cè)信息在文本文檔中以分隔符隔開(kāi)
           }
                File.WriteAllText("Regster.txt", strs);//若只寫(xiě)文檔名字,則默認(rèn)的路徑是在本項(xiàng)目的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)
        {
             //輸入三次錯(cuò)誤后,計(jì)時(shí)器停止輸入3分鐘后再重新輸入
                this.btnregster.Enabled = true;
        }
 
        private void Form1_Activated(object sender, EventArgs e)
       {
            txtname.Focus();//首先讓用戶名文本框獲得焦點(diǎn)
}

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

相關(guān)文章

最新評(píng)論