using System; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; using System.Windows.Forms; namespace anclock { public partial class anclock : Form { bool pb = false; private System.ComponentModel.IContainer components = null; private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.ToolStripMenuItem tsmi1; private System.Windows.Forms.ToolStripMenuItem tsmi2; protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { } public anclock() { this.components = new System.ComponentModel.Container(); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.tsmi1 = new System.Windows.Forms.ToolStripMenuItem(); this.tsmi2 = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); this.pictureBox1.BackColor = System.Drawing.Color.Transparent; this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Margin = new System.Windows.Forms.Padding(0); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(300, 300); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove); this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown); this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp); this.timer1.Interval = 500; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.tsmi1, this.tsmi2 }); this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System; this.contextMenuStrip1.ShowImageMargin = false; this.contextMenuStrip1.Size = new System.Drawing.Size(74, 48); this.tsmi1.Name = "tsmi1"; this.tsmi1.Size = new System.Drawing.Size(73, 22); this.tsmi1.Text = "time"; this.tsmi2.Name = "tsmi2"; this.tsmi2.Size = new System.Drawing.Size(73, 22); this.tsmi2.Text = "Close"; this.tsmi2.Click += new System.EventHandler(this.tsmi2_Click); this.FormBorderStyle = FormBorderStyle.None; this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.ClientSize = new System.Drawing.Size(300, 300); this.ContextMenuStrip = this.contextMenuStrip1; this.Controls.Add(this.pictureBox1); this.Name = "Form1"; this.ShowIcon = false; this.ShowInTaskbar = false; this.Load += new System.EventHandler(this.Form1_Load); this.DragDrop += new System.Windows.Forms.DragEventHandler(this.Form1_DragDrop); this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Form1_DragEnter); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.contextMenuStrip1.ResumeLayout(false); this.ResumeLayout(false); Setbrd(); timer1.Start(); } private void Form1_Load(object sender, EventArgs e) { this.SetBounds(this.Left, this.Top, 301, 301, BoundsSpecified.Size); GraphicsPath path = new GraphicsPath(); path.AddEllipse(new Rectangle(0, 0, 300, 300)); this.Region = new Region(path); this.TopMost = true; } private void Setbrd() { Bitmap img = this.BackgroundImage == null ? new Bitmap(300, 300) : (Bitmap)this.BackgroundImage; Graphics g = Graphics.FromImage(img); int i = 12, l = 130; for (; i > 0; i--) { string st = i.ToString(); Font fn = new Font("Arial Bold", 25); SizeF f = g.MeasureString(st, fn, 50); double rd = - i * Math.PI / 6; PointF p = new PointF((float)(150 - l * Math.Sin(rd) - f.Width / 2), (float)(150 - l * Math.Cos(rd) - f.Height / 2)); g.DrawString(st, fn, Brushes.Black, p); } this.BackgroundImage = img; g.Dispose(); } private Point[] Setneedle(int l, double rd, double r) { rd = -rd; double r1 = rd - r, r2 = rd + r; Point[] p = new Point[3]; p[0] = new Point((int)(150 - l * Math.Sin(rd)), (int)(150 - l * Math.Cos(rd))); p[1] = new Point((int)(150 - 15 * Math.Sin(r1)), (int)(150 - 15 * Math.Cos(r1))); p[2] = new Point((int)(150 - 15 * Math.Sin(r2)), (int)(150 - 15 * Math.Cos(r2))); return p; } private void timer1_Tick(object sender, EventArgs e) { Bitmap img = new Bitmap(300, 300); Graphics g = Graphics.FromImage(img); DateTime d = DateTime.Now; tsmi1.Text = d.ToString(); double rd = (d.Hour % 12) * Math.PI / 6 + d.Minute * Math.PI / 360, r = Math.PI / 4; int l = 80; Point[] p = Setneedle(l, rd, r); g.FillPolygon(Brushes.Black, p); rd = d.Minute * Math.PI / 30; r = Math.PI / 8; l = 110; p = Setneedle(l, rd, r); g.FillPolygon(Brushes.Black, p); rd = d.Second * Math.PI / 30; r = Math.PI / 18; l = 140; p = Setneedle(l, rd, r); g.FillPolygon(Brushes.Black, p); g.FillEllipse(Brushes.Black, 134, 134, 32, 32); pictureBox1.Image = img; g.Dispose(); g = null; GC.Collect(); } private void tsmi2_Click(object sender, EventArgs e) { this.Close(); } private void Form1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } private void Form1_DragDrop(object sender, DragEventArgs e) { string[] fp; fp = (string[])e.Data.GetData(DataFormats.FileDrop, false); if (fp.Length == 0) return; timer1.Stop(); Bitmap img = null;Graphics g = null; try { img = new Bitmap(@fp[0]); g = Graphics.FromImage((Bitmap)this.BackgroundImage); g.DrawImage(img, this.ClientRectangle); Setbrd(); } catch { } finally { if (g != null) g.Dispose(); if (img != null) img.Dispose(); timer1.Start(); } } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (!pb) return; Point p = Cursor.Position; this.Location = new Point(p.X - 150, p.Y - 150); } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) pb = true; } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { pb = false;} } static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new anclock()); } } }