c#创建简易记事本 状态栏显示当前系统时间

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c#创建简易记事本 状态栏显示当前系统时间相关的知识,希望对你有一定的参考价值。

步骤:
1.创建窗体及添加StatusStrip
默认StatusStrip名称为statusStrip1
2.在statusStrip1的Items属性中
添加三个StatusLabel
默认名称为toolStripStatusLabel1,2,3
按1,2,3的顺序排列
3.修改toolStripStatusLabel1的Text属性
为相关文字如"欢迎使用本系统"
4.修改toolStripStatusLabel2的Text属性 为空
Sprint属性为True
BorderSides属性为Left,Right
5.修改toolStripStatusLabel3的Text属性 为空
在Form的Load事件中 修改其显示为当前时间
[csharp] view plain copy
this.toolStripStatusLabel3.Text = "登录时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
6.如果要使状态栏时间信息随操作系统当前时间不停的改变
则可以通过增加Timer控件来实现

增加Timer控件 timer1
编写其Tick事件为
[csharp] view plain copy
private void timer1_Tick(object sender, EventArgs e)



this.toolStripStatusLabel3.Text = "系统当前时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");



在Form的Load事件中 对timer1进行相关设置:
[csharp] view plain copy
private void MainForm_Load(object sender, EventArgs e)



this.toolStripStatusLabel3.Text = "系统当前时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

this.timer1.Interval=1000;

this.timer1.Start();

参考技术A c#创建简易记事本 状态栏显示当前系统时间
假设界面上已经有了一个richTextBox1控件,并且statusstrip已经添加了一个toolStripStatusLabel1

为richTextBox1添加SelectionChanged事件,事件代码如下:
private void richTextBox1_SelectionChanged(object sender, EventArgs e)

int row = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart) + 1;
int start = richTextBox1.GetFirstCharIndexOfCurrentLine();
string s = richTextBox1.Text.Substring(start, richTextBox1.SelectionStart - start);
int col = GetStringLen(s) + 1;
toolStripStatusLabel1.Text = "第 " + row + " 行, 第 " + col + " 列";


/// <summary>
/// 获取字符串s的长度,包括字母,中文,特殊符号等
/// </summary>
/// <param name="s">要获取长度的字符串</param>
/// <returns>字符串的长度</returns>
private int GetStringLen(string s)

if (!string.IsNullOrEmpty(s))

int len = s.Length;
for (int i = 0; i < s.Length; i++)

if (s[i] > 255)
len++;

return len;

return 0;
参考技术B 将下面的放在一个timer事件函数中:
System.DateTime.Now.ToLongDateString();//日期字符串
System.DateTime.Now.ToLongTimeString();//时间字符串
参考技术C http://blog.csdn.net/followingturing/article/details/6691429
上面有个教程,有步骤示例

C# winform 获取标题栏,状态栏,菜单栏的高度

MessageBox.Show("当前窗体标题栏高度"+(this.Height - this.ClientRectangle.Height).ToString());//获得当前窗体标题栏高度
 
 
 
ClientRectangle//获取表示控件的工作区的矩形
 
 
MessageBox.Show(SystemInformation.PrimaryMonitorSize.ToString()); //获取主显示器屏幕的尺寸(像素)   
//获取主显示器当前当前视频模式的尺寸(以象素为单位)
 
MessageBox.Show("菜单栏高度"+SystemInformation.MenuHeight.ToString());  //获取标准菜单栏的高度   
   MessageBox.Show("标题栏高度"+SystemInformation.CaptionHeight.ToString()); //获取标准标题栏的高度   
 
 
 
MenuHeight//获取一个菜单行的高度(以象素为单位)
 
 
 
CaptionHeight//获取窗口的标准标题栏区域的高度(以象素为单位)

以上是关于c#创建简易记事本 状态栏显示当前系统时间的主要内容,如果未能解决你的问题,请参考以下文章

如何更改当前系统时间日期并插入到文本文档中

C#的winform里statusStrip控件怎么显示系统时间?

系统状态栏时间显示周几,想改成星期几,在哪里改

mfc编程怎么可以在状态栏时时显示系统时间

当前控件的工具提示中的 WPF C# 状态栏标签内容

关于Qt:如何在状态栏中加入系统时间或程序运行时间?