上篇增加了文字的繪製,
現在要將文字新增到Pitch刻度的旁邊。
#region Pitch graphics.TranslateTransform(Width / 2f, Height / 2f); graphics.RotateTransform(Roll); var longEdge = Width / 2f / 5f;//30 var shortEdge = longEdge - 10; var offset = Height / 2 / 2f / 15 / 5f * 4.5f;//4.5 var fontSize = Width / 2f / 10f / 5f * 4;//12 for (var a = -90; a <= 90; a += 5) { //每5度為一刻度,以Pitch為中心只顯示+-20度 if (a <= Pitch + 20 && a >= Pitch - 20) { using (var pen = new Pen(Color.White, 3f)) { //每10度加強顯示 var edge = a % 10 == 0 ? longEdge : shortEdge; graphics.DrawLine(pen, new PointF(-edge + 0, 0 + (Pitch - a) * offset), new PointF(edge + 0, 0 + (Pitch - a) * offset)); DrawString(a.ToString(), new Font(Font.FontFamily, fontSize), new SolidBrush(Color.White), -longEdge, (Pitch - a) * offset, graphics, StringAlignment.Right); } } } graphics.ResetTransform(); graphics.TranslateTransform(Width / 2f, Height / 2f); graphics.RotateTransform(Roll);//指標跟著Roll旋轉 var centerRec = new RectangleF(-Width / 4f, -Height / 4f, Width / 2f, Height / 2f); using (var pen = new Pen(Color.Red, 4f)) { //刻度指標 graphics.DrawLine(pen, new PointF(0, 0), new PointF(-longEdge, longEdge / 2f)); graphics.DrawLine(pen, new PointF(0, 0), new PointF(longEdge, longEdge / 2f)); //水平指標 graphics.DrawLine(pen, new PointF(centerRec.Left - longEdge, 0), new PointF(centerRec.Left, 0)); graphics.DrawLine(pen, new PointF(centerRec.Right + longEdge, 0), new PointF(centerRec.Right, 0)); } #endregion
沒有留言:
張貼留言