Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 5k
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_12
  8. {
  9. /// <summary>
  10. /// Form1 的摘要说明。
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.RichTextBox richTextBox1;
  15. private System.Windows.Forms.StatusBar statusBar1;
  16. private System.Windows.Forms.StatusBarPanel sBarTime;
  17. private System.Windows.Forms.Timer timer1;
  18. private System.Windows.Forms.StatusBarPanel sBarKeyState;
  19. private System.Windows.Forms.StatusBarPanel sBarPostion;
  20. private System.ComponentModel.IContainer components;
  21. public Form1()
  22. {
  23. //
  24. // Windows 窗体设计器支持所必需的
  25. //
  26. InitializeComponent();
  27. //
  28. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  29. //
  30. }
  31. /// <summary>
  32. /// 清理所有正在使用的资源。
  33. /// </summary>
  34. protected override void Dispose( bool disposing )
  35. {
  36. if( disposing )
  37. {
  38. if (components != null) 
  39. {
  40. components.Dispose();
  41. }
  42. }
  43. base.Dispose( disposing );
  44. }
  45. #region Windows Form Designer generated code
  46. /// <summary>
  47. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  48. /// 此方法的内容。
  49. /// </summary>
  50. private void InitializeComponent()
  51. {
  52. this.components = new System.ComponentModel.Container();
  53. this.richTextBox1 = new System.Windows.Forms.RichTextBox();
  54. this.statusBar1 = new System.Windows.Forms.StatusBar();
  55. this.sBarPostion = new System.Windows.Forms.StatusBarPanel();
  56. this.sBarTime = new System.Windows.Forms.StatusBarPanel();
  57. this.sBarKeyState = new System.Windows.Forms.StatusBarPanel();
  58. this.timer1 = new System.Windows.Forms.Timer(this.components);
  59. ((System.ComponentModel.ISupportInitialize)(this.sBarPostion)).BeginInit();
  60. ((System.ComponentModel.ISupportInitialize)(this.sBarTime)).BeginInit();
  61. ((System.ComponentModel.ISupportInitialize)(this.sBarKeyState)).BeginInit();
  62. this.SuspendLayout();
  63. // 
  64. // richTextBox1
  65. // 
  66. this.richTextBox1.Cursor = System.Windows.Forms.Cursors.Default;
  67. this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
  68. this.richTextBox1.Name = "richTextBox1";
  69. this.richTextBox1.Size = new System.Drawing.Size(312, 273);
  70. this.richTextBox1.TabIndex = 0;
  71. this.richTextBox1.Text = "";
  72. this.richTextBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.richTextBox1_MouseDown);
  73. this.richTextBox1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.richTextBox1_KeyUp);
  74. // 
  75. // statusBar1
  76. // 
  77. this.statusBar1.Location = new System.Drawing.Point(0, 241);
  78. this.statusBar1.Name = "statusBar1";
  79. this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
  80.   this.sBarPostion,
  81.   this.sBarTime,
  82.   this.sBarKeyState});
  83. this.statusBar1.ShowPanels = true;
  84. this.statusBar1.Size = new System.Drawing.Size(312, 32);
  85. this.statusBar1.TabIndex = 1;
  86. this.statusBar1.Text = "statusBar1";
  87. // 
  88. // sBarPostion
  89. // 
  90. this.sBarPostion.Text = "就绪";
  91. this.sBarPostion.Width = 140;
  92. // 
  93. // sBarTime
  94. // 
  95. this.sBarTime.Text = "time";
  96. // 
  97. // sBarKeyState
  98. // 
  99. this.sBarKeyState.Text = "INS";
  100. // 
  101. // timer1
  102. // 
  103. this.timer1.Enabled = true;
  104. this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
  105. // 
  106. // Form1
  107. // 
  108. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  109. this.ClientSize = new System.Drawing.Size(312, 273);
  110. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  111.   this.statusBar1,
  112.   this.richTextBox1});
  113. this.Name = "Form1";
  114. this.Text = "多功能状态栏";
  115. ((System.ComponentModel.ISupportInitialize)(this.sBarPostion)).EndInit();
  116. ((System.ComponentModel.ISupportInitialize)(this.sBarTime)).EndInit();
  117. ((System.ComponentModel.ISupportInitialize)(this.sBarKeyState)).EndInit();
  118. this.ResumeLayout(false);
  119. }
  120. #endregion
  121. /// <summary>
  122. /// 应用程序的主入口点。
  123. /// </summary>
  124. [STAThread]
  125. static void Main() 
  126. {
  127. Application.Run(new Form1());
  128. }
  129. private void timer1_Tick(object sender, System.EventArgs e)
  130. {
  131. //在状态栏上显示系统时间
  132. DateTime dTime=DateTime.Now;
  133. string s= dTime.ToLongTimeString();
  134. this.sBarTime.Text=s;
  135. }
  136. private void richTextBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
  137. {
  138. //检查键盘信息,如果是Insert就改变状态栏的状态
  139. if (e.KeyCode == Keys.Insert) 
  140. {
  141. string s = this.sBarKeyState.Text;
  142. if (s.Equals("INS"))
  143. this.sBarKeyState.Text = "OVR";
  144. else
  145. this.sBarKeyState.Text = "INS";
  146. }
  147. }
  148. private void richTextBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
  149. {
  150. //检查鼠标位置,改变状态栏
  151. int x=Cursor.Position.X;
  152. int y=Cursor.Position.Y;
  153. this.sBarPostion.Text="鼠标位置 X="+x.ToString()+"  Y="+y.ToString();
  154. }
  155. }
  156. }