📄 clock.cs
字号:
namespace Ch9_7
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Globalization;
using System.Timers;
/// <summary>
/// Summary description for Clock.
/// </summary>
///
public class Clock : System.Windows.Forms.Control
{
private System.Timers.Timer aTimer;
private void InitializeComponent ()
{
}
public Clock()
{
aTimer = new System.Timers.Timer();
aTimer.Tick+=new EventHandler(OnTimedEvent);
// Set the Interval to 1 second.
aTimer.Interval=100;
aTimer.Enabled=true;
}
public void OnTimedEvent(object source, EventArgs e)
{
Invalidate();
}
protected override void OnPaint(PaintEventArgs pe)
{
// Get the current time
DateTime dt = DateTime.Now;
// Format it as a string
string t = dt.ToShortTimeString();
// And display it
StringFormat style = new StringFormat();
style.Alignment = StringAlignment.Center;
pe.Graphics.DrawString(t, Font, new SolidBrush (ForeColor), ClientRectangle, style);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -