/// <summary> /// Paint on the ruler ticks /// </summary> private void RulerHorz_Paint(object sender, PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.FillRectangle(new SolidBrush(RulerHorz.BackColor), e.ClipRectangle); Pen DrawPen = new Pen(Color.Black); SolidBrush TextBrush = new SolidBrush(RulerHorz.ForeColor); RectangleF Rect; string Text = string.Empty; // Determine the offset for the Ruler // First account for the difference in where the ruler's origin is vs the Workspace's origin. int StartTick = pnlWorkspace.Location.X - RulerHorz.Location.X; // Next, determine where the origin of the Canvas is relative to this point StartTick += pnlEasel.Location.X; StartTick += CanvasPane.Location.X; //Debug.WriteLine(CanvasPane.Location); int Tick = 0; int Bump = 0; int TextPos = 0; for (int x = 0; x <= _Document.Scaling.LatticeSize.Width; x++) { Tick = StartTick + (x * _Document.Scaling.CellScale); Bump = (x % 10 == 0) ? 12 : ((x % 10 == 5) ? 8 : 6); e.Graphics.DrawLine(DrawPen, new Point(Tick, RulerHorz.Height - Bump), new Point(Tick, RulerHorz.Height)); if (x % 10 == 0) { Text = x.ToString(); TextPos = RulerHorz.Height - Bump; Rect = new RectangleF(new Point(Tick, TextPos), e.Graphics.MeasureString(Text, RulerHorz.Font)); TextPos -= (int)Rect.Height; Rect.Location = new PointF(Tick - (Rect.Width / 2), TextPos); e.Graphics.DrawString(Text, RulerHorz.Font, TextBrush, Rect, _rulerTextFormatter); } } // If the mouse is over the CanvasPane, draw the position tick mark if (_mouseOverCanvasPane) { Tick = StartTick + _global.CalcCanvasPoint(_global.UI.MousePosition).X; e.Graphics.DrawLine(DrawPen, new Point(Tick, RulerHorz.Top), new Point(Tick, RulerHorz.Height)); } DrawPen?.Dispose(); TextBrush?.Dispose(); }