00001 using System; 00002 using System.Collections.Generic; 00003 using System.ComponentModel; 00004 using System.Data; 00005 using System.Drawing; 00006 using System.Linq; 00007 using System.Text; 00008 using System.Windows.Forms; 00009 00010 namespace CompassDial { 00011 public partial class CompassDialForm : Form { 00012 Bitmap orig; 00013 00014 public CompassDialForm() { 00015 InitializeComponent(); 00016 orig = (Bitmap)compassDialPictureBox.Image; 00017 brush1 = new SolidBrush(Color.Orange); 00018 brush2 = new SolidBrush(Color.Black); 00019 pen = new Pen(brush1, 4); 00020 center = new PointF((float)(compassDialPictureBox.Width / 2 + 2) 00021 , (float)(compassDialPictureBox.Height / 2 + 2)); 00022 f = new Font(FontFamily.GenericMonospace, 32); 00023 textPoint = new PointF(80, 140); 00024 } 00025 00026 private double getRadians(double degrees) { 00027 return (Math.PI / 180) * (degrees - 90); 00028 } 00029 00030 double angle = 0.0; 00031 float x = 0.0F; 00032 float y = 0.0F; 00033 Bitmap b; 00034 Graphics g; 00035 SolidBrush brush1; 00036 SolidBrush brush2; 00037 Pen pen; 00038 Font f; 00039 PointF center; 00040 PointF direction; 00041 PointF textPoint; 00042 00043 public void drawCompassDial(double degrees) { 00044 angle = getRadians(degrees); 00045 x = (float)Math.Cos(angle) * 150 + 150; 00046 y = (float)Math.Sin(angle) * 150 + 150; 00047 direction.X = x + 8; 00048 direction.Y = y + 8; 00049 b = new Bitmap(orig); 00050 g = Graphics.FromImage(b); 00051 g.FillEllipse(brush1, x, y, 16, 16); 00052 g.DrawLine(pen, center, direction); 00053 g.DrawString(degrees.ToString(), f, brush2, textPoint); 00054 compassDialPictureBox.Image = b; 00055 compassDialPictureBox.Invalidate(); 00056 } 00057 } 00058 }