日期:2014-05-17  浏览次数:21003 次

C#个性化时钟控件之2(含源码)

先看效果:


1、首先,定义显示时钟的样式:SevenSegmentClockStyle

//SevenSegmentClockStyle.cs

using System;

namespace BrawDraw.Com.PhotoFrame.Net.PublicFunctions
{
/// <summary>
/// Clock's Style.
/// </summary>
public enum SevenSegmentClockStyle
{
DateOnly,
TimeOnly,
DateAndTime
}
}

如果使用SevenSegmentClockStyle.DateOnly则效果如下:

如果使用SevenSegmentClockStyle.TimeOnly,其效果如下:


2、定义用于显示时间的8字型段码:

//SevenSegmentDisplay.cs



using System;
using System.Drawing;
using System.Windows.Forms;


namespace BrawDraw.Com.PhotoFrame.Net.PublicFunctions
{
class SevenSegmentDisplay
{
Graphics grfx;
Brush _brush = Brushes.Black;
bool _isDrawShadow = true;
Color _shadowColor = Color.FromArgb(60, Color.White);
Brush _shadowBrush = null;


// Indicates what segments are illuminated for all 10 digits


static byte[,] bySegment = {
{1, 1, 1, 0, 1, 1, 1},       // 0
{0, 0, 1, 0, 0, 1, 0},       // 1
{1, 0, 1, 1, 1, 0, 1},       // 2
{1, 0, 1, 1, 0, 1, 1},       // 3
{0, 1, 1, 1, 0, 1, 0},       // 4
{1, 1, 0, 1, 0, 1, 1},       // 5
{1, 1, 0, 1, 1, 1, 1},       // 6
{1, 0, 1, 0, 0, 1, 0},       // 7
{1, 1, 1, 1, 1, 1, 1},       // 8
{1, 1, 1, 1, 0, 1, 1}        // 9
  };
// Points that define each of the seven segments
readonly Point[][] apt = new Point[7][];


public bool IsDrawShadow
{
get { return this._isDrawShadow; }
set { this._isDrawShadow = value; }
}


public SevenSegmentDisplay(Graphics grfx)
{
this.grfx = grfx;


// Initialize jagged Point array.
apt[0] = new Point[] {