代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
C#实现的GDI+时钟
作者:
DDT
/ 发布于
2012/1/29
/
833
<div>using System; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; class Clock { private Point mickeyMouse = new Point(0, 0); private void Form1_Paint(object sender, PaintEventArgs e) { DrawClock(e.Graphics); timer1.Start(); } <div> private void DrawClock(Graphics g) { ///centre(120, 130); Rectangle outRect = new Rectangle(0, 0, 240, 260); Rectangle midRect = new Rectangle(7, 7, 226, 246); Rectangle inRect = new Rectangle(10, 10, 220, 240); LinearGradientBrush outlBlueBrush = new LinearGradientBrush(outRect, Color.FromArgb(0, 0, 100), Color.FromArgb(0, 0, 255), LinearGradientMode.BackwardDiagonal); LinearGradientBrush midlBlueBrush = new LinearGradientBrush(midRect, Color.FromArgb(0, 0, 255), Color.FromArgb(0, 0, 100), LinearGradientMode.BackwardDiagonal); LinearGradientBrush inlBlueBrush = new LinearGradientBrush(inRect, Color.FromArgb(0, 0, 100), Color.FromArgb(0, 0, 255), LinearGradientMode.BackwardDiagonal); g.FillEllipse(outlBlueBrush, outRect); g.FillEllipse(midlBlueBrush, midRect); g.FillEllipse(inlBlueBrush, inRect); outlBlueBrush.Dispose(); midlBlueBrush.Dispose(); inlBlueBrush.Dispose(); Font myFont = new Font("Arial", 20, FontStyle.Bold); SolidBrush whiteBrush = new SolidBrush(Color.White); g.DrawString("12", myFont, whiteBrush, 100, 10); g.DrawString("6", myFont, whiteBrush, 110, 223); g.DrawString("3", myFont, whiteBrush, 210, 120); g.DrawString("9", myFont, whiteBrush, 10, 120); g.DrawString("1", myFont, whiteBrush, 160, 26); g.DrawString("2", myFont, whiteBrush, 194, 64); g.DrawString("5", myFont, whiteBrush, 156, 210); g.DrawString("4", myFont, whiteBrush, 192, 174); g.DrawString("11", myFont, whiteBrush, 55, 28); g.DrawString("10", myFont, whiteBrush, 22, 66); g.DrawString("7", myFont, whiteBrush, 64, 210); g.DrawString("8", myFont, whiteBrush, 28, 174); myFont.Dispose(); whiteBrush.Dispose(); //DateTime; g.TranslateTransform(120, 130, MatrixOrder.Append); Pen hourPen = new Pen(Color.White, 6); hourPen.SetLineCap(LineCap.RoundAnchor, LineCap.ArrowAnchor, DashCap.Flat); Pen minutePen = new Pen(Color.White, 4); minutePen.SetLineCap(LineCap.RoundAnchor, LineCap.ArrowAnchor, DashCap.Flat); Pen secondPen = new Pen(Color.Red, 2); int sec = DateTime.Now.Second; int min = DateTime.Now.Minute; int hour = DateTime.Now.Hour; double secondAngle = 2.0 * Math.PI * sec / 60.0; double minuteAngle = 2.0 * Math.PI * (min + sec / 60.0) / 60.0; double hourAngle = 2.0 * Math.PI * (hour + min / 60.0) / 12.0; Point centre = new Point(0, 0); Point hourHand = new Point((int)(40 * Math.Sin(hourAngle)), (int)(-40 * Math.Cos(hourAngle))); g.DrawLine(hourPen, centre, hourHand); Point minHand = new Point((int)(80 * Math.Sin(minuteAngle)), (int)(-80 * Math.Cos(minuteAngle))); g.DrawLine(minutePen, centre, minHand); Point secHand = new Point((int)(80 * Math.Sin(secondAngle)), (int)(-80 * Math.Cos(secondAngle))); g.DrawLine(secondPen, centre, secHand); hourPen.Dispose(); minutePen.Dispose(); secondPen.Dispose(); } private void timer1_Tick(object sender, EventArgs e) { this.Invalidate(); } private void hideToolStripMenuItem_Click(object sender, EventArgs e) { if (contextMenuStrip1.Items[0].ToString() == "Hide") { this.Hide(); contextMenuStrip1.Items[0].Text = "Show"; return; } if (contextMenuStrip1.Items[0].ToString() == "Show") { this.Show(); contextMenuStrip1.Items[0].Text = "Hide"; return; } } private void Form1_MouseDown(object sender, MouseEventArgs e) { mickeyMouse = new Point(-e.X, -e.Y); } private void Form1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Point mousePos = Control.MousePosition; mousePos.Offset(mickeyMouse.X, mickeyMouse.Y); Location = mousePos; } } private void notifyIcon1_DoubleClick(object sender, EventArgs e) { if (contextMenuStrip1.Items[0].ToString() == "Show") { this.Show(); contextMenuStrip1.Items[0].Text = "Hide"; return; } } }
试试其它关键字
GDI+时钟
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
DDT
贡献的其它代码
(
160
)
.
Oracle统计表的数据行和数据块信息
.
html标签闭合检测与修复
.
Powershell日期计算
.
Powershell的Base64编解码
.
Powershell并行循环
.
Powershell目录中搜索文本
.
Powershell枚举远程机器上的本地权限组
.
VBScript解析csv文件
.
快速排序之Powershell
.
批处理输出格式化时间字符串
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3