参考了好多资料,终于做了一个winform时钟出来,效果图如下:
1,首先在winfrom项目中添加了一个用户控件ClockControl,实现过程可见代码注释,代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace WinClock
{
public partial class ClockControl : UserControl
{
const int screenWidth = 200; //屏幕宽度
const int screenHeight = 200; //屏幕高度
public ClockControl()
{
InitializeComponent();
this.Width = screenWidth + 1;
this.Height = screenHeight + 1;
this.DoubleBuffered = true; //控件缓冲,避免闪烁
this.SetStyle(ControlStyles.ResizeRedraw, true);
cl