c#改写的(vb.net)模拟时钟


所属类别:.NET

文章作者:未知

特别推荐:免费发布信息 承包关键词~~抢爆了!HOT!


ClockControl.csusing System;using System.Windows.Forms;using System.Drawing;using System.Drawing.Drawing2D;namespace ClockTime{/// /// ClockControl 的摘要说明。/// public class ClockControl:System.Windows.Forms.UserControl{private DateTime dt;public ClockControl(){//// TODO: 在此处添加构造函数逻辑//this.ResizeRedraw=true;this.Enabled=false;}public DateTime Time{set{Graphics grfx=this.CreateGraphics();Pen pn=new Pen(this.BackColor);InitializeCoordinates(grfx);if(dt.Hour!=value.Hour){DrawHourHand(grfx,pn);}if(dt.Minute!=value.Minute){DrawHourHand(grfx,pn);DrawMinuteHand(grfx,pn);}if(dt.Second!=value.Second){DrawMinuteHand(grfx,pn);DrawSecondHand(grfx,pn);}if(dt.Millisecond!=value.Millisecond){DrawSecondHand(grfx,pn);}dt=value;pn=new Pen(ForeColor);DrawHourHand(grfx,pn);DrawMinuteHand(grfx,pn);DrawSecondHand(grfx,pn);grfx.Dispose();}get{return dt;}}protected override void OnPaint(PaintEventArgs e){Graphics grfx=e.Graphics;Pen pn=new Pen(ForeColor);SolidBrush br=new SolidBrush(ForeColor);InitializeCoordinates(grfx);DrawDots(grfx,br);DrawHourHand(grfx,pn);DrawSecondHand(grfx,pn);DrawMinuteHand(grfx,pn);}protected virtual void InitializeCoordinates(Graphics grfx){if(this.Width==0 this.Height==0) return;grfx.TranslateTransform(this.Width/2,this.Height/2);Single fInches=Math.Min(this.Width/grfx.DpiX,this.Height/grfx.DpiY);grfx.ScaleTransform(fInches*grfx.DpiX/2000,fInches*grfx.DpiY/2000);}protected virtual void DrawDots(Graphics grfx ,Brush br){int i,iSize;for(i=0;i<=59;i++){if(i%5==0){iSize=100;}elseiSize=30;grfx.FillEllipse(br,0-iSize/2,-900-iSize/2,iSize,iSize);grfx.RotateTransform(6);}}protected virtual void DrawHourHand(Graphics grfx,Pen pn){GraphicsState gs=grfx.Save();grfx.RotateTransform(360.0F*Time.Hour/12+30.0F*Time.Minute/60);grfx.DrawPolygon(pn,new Point[]{new Point(0,150),new Point(100,0),new Point(0,-600),new Point(-100,0)});grfx.Restore(gs);}protected virtual void DrawMinuteHand(Graphics grfx,Pen pn){GraphicsState gs=grfx.Save();grfx.RotateTransform(360.0F*Time.Minute/60+6.0F*Time.Second/60);grfx.DrawPolygon(pn,new Point[]{new Point(0,200),new Point(50,0),new Point(0,-800),new Point(-50,0)});grfx.Restore(gs);}protected virtual void DrawSecondHand(Graphics grfx,Pen pn){GraphicsState gs=grfx.Save();grfx.RotateTransform(360.0F*Time.Second/60+6.0F*Time.Millisecond/1000);grfx.DrawLine(pn,0,0,0,-800);grfx.Restore(gs);}}}form1.csusing System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using ClockTime;namespace ClockTime{/// /// Form1 的摘要说明。/// public class Form1 : System.Windows.Forms.Form{private System.ComponentModel.IContainer components;private System.Windows.Forms.Timer tmr;private ClockTime.ClockControl clkctrl;public Form1(){//// Windows 窗体设计器支持所必需的//InitializeComponent();//// TODO: 在 InitializeComponent 调用后添加任何构造函数代码//}/// /// 清理所有正在使用的资源。/// protected override void Dispose( bool disposing ){if( disposing ){if (components != null){components.Dispose();}}base.Dispose( disposing );}#region Windows 窗体设计器生成的代码/// /// 设计器支持所需的方法 - 不要使用代码编辑器修改/// 此方法的内容。/// private void InitializeComponent(){this.components = new System.ComponentModel.Container();this.clkctrl = new ClockTime.ClockControl();this.tmr = new System.Windows.Forms.Timer(this.components);this.SuspendLayout();//// clkctrl//this.clkctrl.BackColor = System.Drawing.Color.Black;this.clkctrl.Dock = System.Windows.Forms.DockStyle.Fill;this.clkctrl.Enabled = false;this.clkctrl.ForeColor = System.Drawing.Color.White;this.clkctrl.Location = new System.Drawing.Point(0, 0);this.clkctrl.Name = "clkctrl";this.clkctrl.Size = new System.Drawing.Size(292, 273);this.clkctrl.TabIndex = 0;this.clkctrl.Time = new System.DateTime(2005, 6, 24, 10, 19, 26, 62);//// tmr//this.tmr.Enabled = true;this.tmr.Interval = 1000;this.tmr.Tick += new System.EventHandler(this.tmr_Tick);//// Form1//this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);this.BackColor = System.Drawing.SystemColors.Window;this.ClientSize = new System.Drawing.Size(292, 273);this.Controls.Add(this.clkctrl);this.ForeColor = System.Drawing.SystemColors.WindowText;this.Name = "Form1";this.Text = "ClockControl";this.ResumeLayout(false);}#endregion/// /// 应用程序的主入口点。/// [STAThread]static void Main(){Application.Run(new Form1());}private void tmr_Tick(object sender, EventArgs e){clkctrl.Time=DateTime.Now;}}}编译过程:csc /t:library clockcontrol.cscsc /t:winexe /r:clockcontrol.dll form1.cs关闭本页

相关信息

· oracle配置的几个教训(增加中)

·  C

· 高手进阶:Redhat Linux上vsftpd编译安装

· 免费午餐:网上免费打电话集合








....

58747 62813