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

首頁 > 編程 > C# > 正文

C#入門之窗體的簡單用法實(shí)例

2020-01-24 02:13:54
字體:
供稿:網(wǎng)友

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

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

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

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

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

把注冊信息的各個(gè)數(shù)據(jù)按照     Rocky|admin|renyanlei@aliyun.com|18301412747|男|足球,籃球,排球”寫入到一個(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á)到三次則注冊按鈕將不能使用
            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)入下一個(gè)界面
                if (string.IsNullOrEmpty(user))
                {
                    MessageBox.Show("注冊失敗,未輸入用戶名!");
                    ++num; //計(jì)時(shí)器的累加
                }
 
                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的窗體,這里傳入一個(gè)參數(shù)user。
                   fm.Show();
                   this.Hide();    //隱藏Form1的窗體 
             }
           //創(chuàng)建一個(gè)Regster文本文檔,并寫入注冊信息,且以分隔符(|)隔開
                string gender = string.Empty;
                string like = string.Empty;
              //判斷性別被選中的是哪個(gè),就獲取哪個(gè)的文本
                if (radman.Checked == true)
                {
                    gender = radman.Text;
                }
                else
                {
                    gender = radwomen.Text;
                }
              //判斷愛好哪幾個(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ù)組來接收注冊信息的數(shù)據(jù)
                string strs = string.Empty;
                foreach (var item in array)
               {
                    strs += item;
                    strs = string.Join("|",array);//注冊信息在文本文檔中以分隔符隔開
           }
                File.WriteAllText("Regster.txt", strs);//若只寫文檔名字,則默認(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)
}

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 吉隆县| 石景山区| 长葛市| 佛坪县| 营口市| 都兰县| 杭锦旗| 常熟市| 沭阳县| 太康县| 清涧县| 青河县| 黄浦区| 稻城县| 绥德县| 饶河县| 乐东| 莱芜市| 尚志市| 大安市| 怀集县| 社会| 政和县| 甘谷县| 毕节市| 应用必备| 开封市| 宜阳县| 荥经县| 绥阳县| 驻马店市| 丹寨县| 浮梁县| 桦川县| 海兴县| 文昌市| 丽江市| 东辽县| 通榆县| 长阳| 久治县|