| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1074 人关注过本帖
标题:怎样把系统时间现实在状态条里
只看楼主 加入收藏
laplas
Rank: 1
等 级:新手上路
帖 子:110
专家分:0
注 册:2006-2-28
收藏
 问题点数:0 回复次数:7 
怎样把系统时间现实在状态条里
如体琐事。谢谢
搜索更多相关主题的帖子: 系统 状态 现实 时间 
2006-04-24 10:48
天气预报不准
Rank: 1
等 级:新手上路
帖 子:200
专家分:0
注 册:2006-3-16
收藏
得分:0 

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace clock
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Timers.Timer Clock;
private System.Windows.Forms.Label lbTime;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lbTime = new System.Windows.Forms.Label();
this.Clock = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.Clock)).BeginInit();
this.SuspendLayout();
//
// lbTime
//
this.lbTime.Font = new System.Drawing.Font("Arial", 42F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lbTime.Name = "lbTime";
this.lbTime.Size = new System.Drawing.Size(300, 130);
this.lbTime.TabIndex = 0;
this.lbTime.Text = "dd:dd:dd";
this.lbTime.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// Clock
//
this.Clock.Enabled = true;
this.Clock.Interval = 1000;
this.Clock.SynchronizingObject = this;
this.Clock.Elapsed += new System.Timers.ElapsedEventHandler(this.Clock_Elapsed);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(290, 131);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.lbTime});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "时钟";
((System.ComponentModel.ISupportInitialize)(this.Clock)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

public string GetTime()
{
string TimeInString="";
int hour=DateTime.Now.Hour;
int min=DateTime.Now.Minute;
int sec=DateTime.Now.Second;

TimeInString=(hour < 10)?"0" + hour.ToString() :hour.ToString();
TimeInString+=":" + ((min<10)?"0" + min.ToString() :min.ToString());
TimeInString+=":" + ((sec<10)?"0" + sec.ToString() :sec.ToString());
return TimeInString;
}

private void Clock_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if(sender==Clock)
{
lbTime.Text=GetTime();
}
}
}
}


哎!发型有点乱。。。。。。
2006-04-24 11:01
laplas
Rank: 1
等 级:新手上路
帖 子:110
专家分:0
注 册:2006-2-28
收藏
得分:0 
要修改这么一大堆东西?有简单点的马
2006-04-24 11:09
laplas
Rank: 1
等 级:新手上路
帖 子:110
专家分:0
注 册:2006-2-28
收藏
得分:0 
这个控件的名称叫什么
2006-04-24 11:13
zjs521
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2006-4-24
收藏
得分:0 

1 加 timer 控件
2 加一个statusbar
3 在 statusbar 中加 个时间按扭 sbp1
4 在form 的showpanel 设为true
5 在timer 中 写 代码
DateTime time1 = DateTime.Now;

string s = time1.ToLongTimeString();

this.sbp1.Text=s;
6运行就成功了

2006-04-24 12:51
水中游
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:149
专家分:0
注 册:2006-3-20
收藏
得分:0 
不错的详解
记下了

锻炼中学习……学习中成长……
2006-04-24 14:12
mapple
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2006-3-16
收藏
得分:0 
5楼的朋友说的很好,谢谢又教了我一招,
不过好像有点问题,就是第四点:
在form 的showpanel 设为true
应该是这样吧:
在statusbar的showpanel 设为true
2006-04-26 15:07
laplas
Rank: 1
等 级:新手上路
帖 子:110
专家分:0
注 册:2006-2-28
收藏
得分:0 
谢谢5楼的。还有个问题,怎么把状态条,分成2段。改那个属性?
2006-04-27 08:38
快速回复:怎样把系统时间现实在状态条里
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017441 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved