小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

C# TextBox事件實(shí)現(xiàn)實(shí)例詳解 - C# - 編程開發(fā) - 伊甸網(wǎng)

 昵稱pds9i 2010-07-16

 C# TextBox事件是我們?cè)陂_發(fā)中會(huì)碰到的具體的功能需求,那么如何使得想要的C# TextBox事件執(zhí)行呢?那么這里就向你介紹具體的C# TextBox事件演示實(shí)例,包括需求的實(shí)現(xiàn),希望對(duì)你有所幫助。

  C# TextBox事件具體的需求:

  ◆界面要求:定義5個(gè)TEXTBOX,分別是:姓名、地址、職業(yè)、年齡、輸出內(nèi)容。1個(gè)BUTTON

  ◆滿足條件:

  (1)用戶名不能為空

  (2)年齡必須是一個(gè)大于或等于0的數(shù)字

  (3)職業(yè)必須是“程序員”或?yàn)榭?/p>

  (4)地址不能為空

  C# TextBox事件實(shí)例實(shí)現(xiàn):

  using System;

  using System.Collections.Generic;  using System.ComponentModel;

  using System.Data;

  using System.Drawing;

  using System.Text;

  using System.Windows.Forms;

  namespace Chapter14  ...

  {

  public partial class Form1 : Form  ...

  {

  public Form1()  ...

  {

  InitializeComponent();

  this.button1.Enabled = false;

  this.textBox1.Tag = false;

  this.textBox2.Tag = false;

  this.textBox3.Tag = false;

  this.textBox4.Tag = false;

  this.textBox1.Validating+=   new System.ComponentModel.CancelEventHandler(  this.textboxEmpty_Validating);

  this.textBox2.Validating +=   new System.ComponentModel.CancelEventHandler(  this.textboxEmpty_Validating);

  this.textBox3.Validating+=   new System.ComponentModel.CancelEventHandler(  this.textboxOccupation_Validating);

  this.textBox4.Validating +=   new System.ComponentModel.CancelEventHandler(  this.textboxEmpty_Validating);

  this.textBox1.TextChanged +=   new System.EventHandler(this.textbox_TextChanged);

  this.textBox4.TextChanged +=   new System.EventHandler(this.textbox_TextChanged);

  this.textBox3.TextChanged +=   new System.EventHandler(this.textbox_TextChanged);

  }

  //C# TextBox事件  private void textboxOccupation_Validating(  object sender,   System.ComponentModel.CancelEventArgs e)

  ...

  {

  TextBox tb=(TextBox)sender;

  if (tb.Text.CompareTo("Programmer") == 0||tb.Text.Length==0)  ...

  {

  tb.Tag = true;

  tb.BackColor = System.Drawing.SystemColors.Window;

  }

  else ...

  {

  tb.Tag = false;

  tb.BackColor = Color.Red;

  }

  ValidateOk();

  }

  //C# TextBox事件  private void textboxEmpty_Validating(  object sender,   System.ComponentModel.CancelEventArgs e)  ...

  {

  TextBox tb = (TextBox)sender;

  if (tb.Text.Length == 0)  ...

  {

  tb.BackColor = Color.Red;

  tb.Tag = false;

  }

  else ...

  {

  tb.BackColor = System.Drawing.SystemColors.Window;

  tb.Tag = true;

  }

  ValidateOk();

  }

  private void textboxAge_KeyPress(  object sender, KeyPressEventArgs e)  ...

  {

  if ((e.KeyChar < 48 || e.KeyChar > 57) &&   e.KeyChar != 8)

  e.Handled = true;

  }

  private void textbox_TextChanged(  object sender, System.EventArgs e)  ...

  {

  TextBox tb = (TextBox)sender;

  if (tb.Text.Length == 0&& tb!=textBox3)  ...

  {

  tb.Tag = false;  tb.BackColor = Color.Red;

  }

  else if (tb == this.textBox3 &&   (tb.Text.Length != 0 &&   tb.Text.CompareTo("Programmer") != 0))  ...

  {

  tb.Tag = false;

  }

  //C# TextBox事件  else ...

  {

  tb.Tag = true;

  tb.BackColor = SystemColors.Window;

  }

  ValidateOk();

  }

  private void ValidateOk()  ...

  {

  this.button1.Enabled =   ((bool)(this.textBox2.Tag) &&   (bool)(this.textBox4.Tag) &&   (bool)(this.textBox1.Tag) &&   (bool)(this.textBox3.Tag));

  }

  private void button1_Click(  object sender, EventArgs e)  ...

  {

  string output;

  //C# TextBox事件

  output = "Name:" + this.textBox1.Text + " ";

  output += "Address:" + this.textBox2.Text + " ";

  output += "Occupation:" + this.textBox3.Text + " ";

  output += "Age:" + this.textBox4.Text + " ";

  this.textBox5.Text = output;

  }

  }

  }

  C# TextBox事件實(shí)現(xiàn)的具體實(shí)例就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C# TextBox事件有所幫助。

本文地址:【伊甸網(wǎng)】http://www./tech/devdeloper/Cp/2010-07-16/4753.html

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多