Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 7k
Category:

ADO-ODBC

Development Platform:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. namespace ch1_17
  8. {
  9. /// <summary>
  10. /// Form1 的摘要说明。
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.ErrorProvider errorProvider1;
  15. private System.Windows.Forms.Label label1;
  16. private System.Windows.Forms.TextBox textBox1;
  17. private System.Windows.Forms.Button button1;
  18. private System.Windows.Forms.Label label2;
  19. private System.Windows.Forms.TextBox textBox2;
  20. private System.Windows.Forms.Label label3;
  21. private System.Windows.Forms.Label labelUser;
  22. private System.Windows.Forms.TextBox textBoxUser;
  23. private System.Windows.Forms.Label labelNote;
  24. /// <summary>
  25. /// 必需的设计器变量。
  26. /// </summary>
  27. private System.ComponentModel.Container components = null;
  28. public Form1()
  29. {
  30. //
  31. // Windows 窗体设计器支持所必需的
  32. //
  33. InitializeComponent();
  34. //
  35. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  36. //
  37. }
  38. /// <summary>
  39. /// 清理所有正在使用的资源。
  40. /// </summary>
  41. protected override void Dispose( bool disposing )
  42. {
  43. if( disposing )
  44. {
  45. if (components != null) 
  46. {
  47. components.Dispose();
  48. }
  49. }
  50. base.Dispose( disposing );
  51. }
  52. #region Windows Form Designer generated code
  53. /// <summary>
  54. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  55. /// 此方法的内容。
  56. /// </summary>
  57. private void InitializeComponent()
  58. {
  59. this.errorProvider1 = new System.Windows.Forms.ErrorProvider();
  60. this.label1 = new System.Windows.Forms.Label();
  61. this.textBox1 = new System.Windows.Forms.TextBox();
  62. this.button1 = new System.Windows.Forms.Button();
  63. this.label2 = new System.Windows.Forms.Label();
  64. this.textBox2 = new System.Windows.Forms.TextBox();
  65. this.label3 = new System.Windows.Forms.Label();
  66. this.labelNote = new System.Windows.Forms.Label();
  67. this.labelUser = new System.Windows.Forms.Label();
  68. this.textBoxUser = new System.Windows.Forms.TextBox();
  69. this.SuspendLayout();
  70. // 
  71. // errorProvider1
  72. // 
  73. this.errorProvider1.ContainerControl = this;
  74. // 
  75. // label1
  76. // 
  77. this.label1.Location = new System.Drawing.Point(48, 112);
  78. this.label1.Name = "label1";
  79. this.label1.Size = new System.Drawing.Size(104, 23);
  80. this.label1.TabIndex = 0;
  81. this.label1.Text = "请设定您的密码";
  82. // 
  83. // textBox1
  84. // 
  85. this.textBox1.Location = new System.Drawing.Point(184, 112);
  86. this.textBox1.Name = "textBox1";
  87. this.textBox1.PasswordChar = '*';
  88. this.textBox1.Size = new System.Drawing.Size(152, 21);
  89. this.textBox1.TabIndex = 2;
  90. this.textBox1.Text = "";
  91. // 
  92. // button1
  93. // 
  94. this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  95. this.button1.Location = new System.Drawing.Point(224, 208);
  96. this.button1.Name = "button1";
  97. this.button1.Size = new System.Drawing.Size(112, 24);
  98. this.button1.TabIndex = 4;
  99. this.button1.Text = "确定";
  100. this.button1.Click += new System.EventHandler(this.button1_Click);
  101. // 
  102. // label2
  103. // 
  104. this.label2.Location = new System.Drawing.Point(48, 160);
  105. this.label2.Name = "label2";
  106. this.label2.TabIndex = 3;
  107. this.label2.Text = "请确认您的密码";
  108. // 
  109. // textBox2
  110. // 
  111. this.textBox2.Location = new System.Drawing.Point(184, 152);
  112. this.textBox2.Name = "textBox2";
  113. this.textBox2.PasswordChar = '*';
  114. this.textBox2.Size = new System.Drawing.Size(152, 21);
  115. this.textBox2.TabIndex = 3;
  116. this.textBox2.Text = "";
  117. // 
  118. // label3
  119. // 
  120. this.errorProvider1.SetIconAlignment(this.label3, System.Windows.Forms.ErrorIconAlignment.BottomLeft);
  121. this.label3.Location = new System.Drawing.Point(48, 216);
  122. this.label3.Name = "label3";
  123. this.label3.Size = new System.Drawing.Size(160, 23);
  124. this.label3.TabIndex = 5;
  125. // 
  126. // labelNote
  127. // 
  128. this.labelNote.Location = new System.Drawing.Point(48, 72);
  129. this.labelNote.Name = "labelNote";
  130. this.labelNote.Size = new System.Drawing.Size(296, 23);
  131. this.labelNote.TabIndex = 6;
  132. this.labelNote.Text = "请注意:密码的位数应大于等于6位且不超过12位";
  133. // 
  134. // labelUser
  135. // 
  136. this.labelUser.Location = new System.Drawing.Point(48, 32);
  137. this.labelUser.Name = "labelUser";
  138. this.labelUser.TabIndex = 7;
  139. this.labelUser.Text = "用户名";
  140. // 
  141. // textBoxUser
  142. // 
  143. this.textBoxUser.Location = new System.Drawing.Point(184, 32);
  144. this.textBoxUser.Name = "textBoxUser";
  145. this.textBoxUser.Size = new System.Drawing.Size(152, 21);
  146. this.textBoxUser.TabIndex = 1;
  147. this.textBoxUser.Text = "";
  148. // 
  149. // Form1
  150. // 
  151. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  152. this.ClientSize = new System.Drawing.Size(384, 277);
  153. this.Controls.Add(this.textBoxUser);
  154. this.Controls.Add(this.labelUser);
  155. this.Controls.Add(this.labelNote);
  156. this.Controls.Add(this.label3);
  157. this.Controls.Add(this.textBox2);
  158. this.Controls.Add(this.label2);
  159. this.Controls.Add(this.button1);
  160. this.Controls.Add(this.textBox1);
  161. this.Controls.Add(this.label1);
  162. this.Name = "Form1";
  163. this.Text = "错误提醒";
  164. this.ResumeLayout(false);
  165. }
  166. #endregion
  167. /// <summary>
  168. /// 应用程序的主入口点。
  169. /// </summary>
  170. [STAThread]
  171. static void Main() 
  172. {
  173. Application.Run(new Form1());
  174. }
  175. private void button1_Click(object sender, System.EventArgs e)
  176. {
  177. if (this.textBoxUser.Text=="")
  178. {
  179. //设置指定控件的错误描述字符串,以下相同
  180. this.errorProvider1.SetError(this.textBoxUser,"请输入用户名");
  181.             this.label3.Text="注册失败";
  182. }
  183. //先判断两个字符串是否相等,然后再判断它们的长度
  184. if (this.textBox1.Text!=this.textBox2.Text)
  185. {
  186. this.errorProvider1.SetError(this.textBox2,"您的确认密码和密码设置得不一样");
  187. this.label3.Text="注册失败";
  188. Reset();
  189. }
  190. else
  191. {
  192. if (this.textBox1.Text.Length<6)
  193. {
  194. this.errorProvider1.SetError(this.textBox2,"您输入的密码位数太少,请重新设定");
  195. this.label3.Text="注册失败";
  196. Reset();
  197. }
  198. else 
  199. {
  200. if (this.textBox1.Text.Length>12)
  201. {
  202. this.errorProvider1.SetError(this.textBox2,"您输入的密码位数太长,请重新设定");
  203. this.label3.Text="注册失败";
  204. Reset();
  205. }
  206. else 
  207. {
  208. //必须将错误提示字符串设为空,否则出现错误之后,即使再成功,错误图标也去不掉
  209. this.errorProvider1.SetError(this.textBox2,"");
  210.     this.label3.Text="欢迎你 "+this.textBoxUser.Text+"!";
  211. }
  212. }
  213. }
  214. }
  215. private void Reset()
  216. {
  217. //如果发生了错误,则清空textBox1和textBox2的文本
  218. this.textBox1.Text="";
  219. this.textBox2.Text="";
  220. }
  221. }
  222. }