在Roll的刻度上方加入文字,
並且讓一些數字與長寬連動,之後變更長寬時仍會維持原本的比例。
#region Roll int[] angles = { -60, -45, -30, -20, -10, 0, 10, 20, 30, 45, 60 }; //要顯示的角度陣列 var angleHeight = 25f * offset; //畫角度的啟始高度,最高的Pitch刻度再高一些(在這是+20度外加位移5,所以取25) var angleLine = offset;//4.5 //線條的長度 foreach (var angle in angles) { graphics.ResetTransform(); graphics.TranslateTransform(Width / 2f, Height / 2f); graphics.RotateTransform(angle + Roll); using (var pen = new Pen(Color.White, 2f)) { graphics.DrawLine(pen, 0, -angleHeight, 0, -angleHeight - angleLine); //旋轉畫面後再畫刻度,線條往上畫,所以減線條長度值 DrawString(angle.ToString(), new Font(Font.FontFamily, fontSize), new SolidBrush(Color.White), offset / 5 * 3.75f, -angleHeight - angleLine * 2, graphics, StringAlignment.Center); } } graphics.ResetTransform(); graphics.TranslateTransform(Width / 2f, Height / 2f); var arcRect = new RectangleF(-angleHeight, -angleHeight, angleHeight * 2, angleHeight * 2); //因為刻度都是以angleHeight為半徑, //所以Rectangle的XY以(angleHeight,angleHeight)為啟始點 //長寬為angleHeight的兩倍,正方矩形。 using (var pen = new Pen(Color.White, 2f)) { graphics.DrawArc(pen, arcRect, -150f + Roll, 120f); //顯示角度為+-60,所以全長為120度,然後向左旋轉150度 } graphics.ResetTransform(); graphics.TranslateTransform(Width / 2f, Height / 2f); using (var pen = new Pen(Color.Red, 2f)) { //畫三角指標 var arrowWidth = 8f; var points = new PointF[3]; points[0] = new PointF(0, -angleHeight); points[1] = new PointF(arrowWidth, -angleHeight + arrowWidth); points[2] = new PointF(-arrowWidth, -angleHeight + arrowWidth); graphics.DrawPolygon(pen, points); } #endregion
沒有留言:
張貼留言