日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
C#TextBox事件實(shí)現(xiàn)實(shí)例詳解

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

公司主營(yíng)業(yè)務(wù):成都網(wǎng)站建設(shè)、做網(wǎng)站、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。成都創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出湘陰免費(fèi)做網(wǎng)站回饋大家。

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):

 
 
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. namespace Chapter14  
  9. ...{  
  10. public partial class Form1 : Form  
  11. ...{  
  12. public Form1()  
  13. ...{  
  14. InitializeComponent();  
  15. this.button1.Enabled = false;  
  16. this.textBox1.Tag = false;  
  17. this.textBox2.Tag = false;  
  18. this.textBox3.Tag = false;  
  19. this.textBox4.Tag = false;  
  20. this.textBox1.Validating+=   
  21. new System.ComponentModel.CancelEventHandler(  
  22. this.textboxEmpty_Validating);  
  23. this.textBox2.Validating +=   
  24. new System.ComponentModel.CancelEventHandler(  
  25. this.textboxEmpty_Validating);  
  26. this.textBox3.Validating+=   
  27. new System.ComponentModel.CancelEventHandler(  
  28. this.textboxOccupation_Validating);  
  29. this.textBox4.Validating +=   
  30. new System.ComponentModel.CancelEventHandler(  
  31. this.textboxEmpty_Validating);  
  32. this.textBox1.TextChanged +=   
  33. new System.EventHandler(this.textbox_TextChanged);  
  34. this.textBox4.TextChanged +=   
  35. new System.EventHandler(this.textbox_TextChanged);  
  36. this.textBox3.TextChanged +=   
  37. new System.EventHandler(this.textbox_TextChanged);  
  38. }  
  39. //C# TextBox事件  
  40. private void textboxOccupation_Validating(  
  41. object sender,   
  42. System.ComponentModel.CancelEventArgs e)  
  43. ...{  
  44. TextBox tb=(TextBox)sender;  
  45. if (tb.Text.CompareTo("Programmer") == 0||tb.Text.Length==0)  
  46. ...{  
  47. tb.Tag = true;  
  48. tb.BackColor = System.Drawing.SystemColors.Window;  
  49.  
  50.  
  51. }  
  52. else 
  53. ...{  
  54. tb.Tag = false;  
  55. tb.BackColor = Color.Red;  
  56.  
  57. }  
  58. ValidateOk();  
  59. }  
  60. //C# TextBox事件  
  61. private void textboxEmpty_Validating(  
  62. object sender,   
  63. System.ComponentModel.CancelEventArgs e)  
  64. ...{  
  65. TextBox tb = (TextBox)sender;  
  66. if (tb.Text.Length == 0)  
  67. ...{  
  68. tb.BackColor = Color.Red;  
  69. tb.Tag = false;  
  70. }  
  71. else 
  72. ...{  
  73. tb.BackColor = System.Drawing.SystemColors.Window;  
  74. tb.Tag = true;  
  75. }  
  76. ValidateOk();  
  77. }  
  78. private void textboxAge_KeyPress(  
  79. object sender, KeyPressEventArgs e)  
  80. ...{  
  81. if ((e.KeyChar < 48 || e.KeyChar > 57) &&   
  82. e.KeyChar != 8)  
  83. e.Handled = true;  
  84. }  
  85. private void textbox_TextChanged(  
  86. object sender, System.EventArgs e)  
  87. ...{  
  88. TextBox tb = (TextBox)sender;  
  89. if (tb.Text.Length == 0&& tb!=textBox3)  
  90. ...{  
  91. tb.Tag = false;  
  92. tb.BackColor = Color.Red;  
  93.  
  94. }  
  95. else if (tb == this.textBox3 &&   
  96. (tb.Text.Length != 0 &&   
  97. tb.Text.CompareTo("Programmer") != 0))  
  98. ...{  
  99. tb.Tag = false;  
  100. }  
  101. //C# TextBox事件  
  102. else 
  103. ...{  
  104. tb.Tag = true;  
  105. tb.BackColor = SystemColors.Window;  
  106. }  
  107. ValidateOk();  
  108. }  
  109. private void ValidateOk()  
  110. ...{  
  111. this.button1.Enabled =   
  112. ((bool)(this.textBox2.Tag) &&   
  113. (bool)(this.textBox4.Tag) &&   
  114. (bool)(this.textBox1.Tag) &&   
  115. (bool)(this.textBox3.Tag));  
  116. }  
  117.  
  118. private void button1_Click(  
  119. object sender, EventArgs e)  
  120. ...{  
  121. string output;  
  122.   //C# TextBox事件  
  123. output = "Name:" + this.textBox1.Text + " ";  
  124. output += "Address:" + this.textBox2.Text + " ";  
  125. output += "Occupation:" + this.textBox3.Text + " ";  
  126. output += "Age:" + this.textBox4.Text + " ";  
  127. this.textBox5.Text = output;  
  128.  
  129. }  
  130. }  
  131. }  

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

【編輯推薦】

  1. 詳解C# MessageBox用法
  2. 詳解C# CheckBox選中的判斷方法
  3. C# CheckBox控件概念以及用途淺析
  4. 學(xué)習(xí)C# MessageBox用法的一點(diǎn)體會(huì)
  5. 淺析C# TextBox事件實(shí)現(xiàn)體會(huì)

當(dāng)前文章:C#TextBox事件實(shí)現(xiàn)實(shí)例詳解
分享地址:http://www.dlmjj.cn/article/dhjeiic.html