如何使用StatusBar控件
我们来看下 定义
public class StatusBar : System.Windows.Forms.Control System.Windows.Forms 的成员 摘要: 表示 Windows 状态栏控件。
从工具栏中拽一个StatusBar 控件
在它的属性中 Panels 中 添加3项
并且更改 各自的Text的值
再来看下代码
private void menuItem2_Click(object sender, System.EventArgs e) {//打开文本文件 this.openFileDialog1.ShowDialog(); string StrFileName=this.openFileDialog1.FileName; if(StrFileName.Trim()=="") return; this.richTextBox1.LoadFile(StrFileName,RichTextBoxStreamType.PlainText); this.statusBarPanel1.Text="文件名:"+StrFileName; }
private void richTextBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {//检测鼠标的位置 int xPos=Cursor.Position.X; int yPos=Cursor.Position.Y; this.statusBarPanel2.Text="鼠标位置:X="+xPos.ToString()+" Y="+yPos.ToString(); }
private void richTextBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) {//检测键盘按键状态 string StrInfo="当前按键为:"; switch(e.KeyCode) { case Keys.A: StrInfo+="A键"; break; case Keys.B: StrInfo+="B键"; break; case Keys.C: StrInfo+="C键"; break; case Keys.D: StrInfo+="D键"; break; case Keys.E: StrInfo+="E键"; break; case Keys.F: StrInfo+="F键"; break; case Keys.G: StrInfo+="G键"; break; case Keys.H: StrInfo+="H键"; break; case Keys.I: StrInfo+="I键"; break; case Keys.J: StrInfo+="J键"; break; case Keys.K: StrInfo+="K键"; break; case Keys.L: StrInfo+="L键"; break; case Keys.M: StrInfo+="M键"; break; case Keys.N: StrInfo+="N键"; break; case Keys.O: StrInfo+="O键"; break; case Keys.P: StrInfo+="P键"; break; case Keys.Q: StrInfo+="Q键"; break; case Keys.R: StrInfo+="R键"; break; case Keys.S: StrInfo+="S键"; break; case Keys.T: StrInfo+="T键"; break; case Keys.U: StrInfo+="U键"; break; case Keys.V: StrInfo+="V键"; break; case Keys.W: StrInfo+="W键"; break; case Keys.X: StrInfo+="X键"; break; case Keys.Y: StrInfo+="Y键"; break; case Keys.Z: StrInfo+="Z键"; break; default: StrInfo+="非字母键"; break; }
public System.Windows.Forms.Keys KeyCode [ get]
System.Windows.Forms.KeyEventArgs 的成员
摘要:
获取 System.Windows.Forms.Control.KeyDown 或 System.Windows.Forms.Control.KeyUp 事件的键盘代码。