/// <summary> /// draws the ruler /// </summary> private void DrawRulerUnits(PaintEventArgs e) { int unit = 1, //starting unit count index = 0; //subdivision count float unitwidth = _zoom.Scale((float)unit); if (unitwidth == 0f) { return; //error } for (; unitwidth <= 60f && index < 1000; index++) { unitwidth *= multipliers[index % multipliers.Length]; unit = (int)(unit * multipliers[index % multipliers.Length]); } //start one unit off the control int startunit = -(_zoom.Unscale(_offset) / unit) * unit - unit; using (StringFormat fmt = new StringFormat(StringFormatFlags.NoWrap)) { fmt.LineAlignment = StringAlignment.Center; fmt.Alignment = StringAlignment.Near; //draw horizontal if (_orientation == Orientation.Horizontal) { for (float x = _zoom.Scale((float)startunit) + (float)_offset; x < this.Width; x += unitwidth, startunit += unit) { DrawXLines(e.Graphics, x, unitwidth, this.Height - 1, index + 1); e.Graphics.DrawString(startunit.ToString(), this.Font, Brushes.Black, new RectangleF(x, 0f, 60f, this.Height / 2), fmt); } } //draw vertical else { fmt.FormatFlags |= StringFormatFlags.DirectionVertical; for (float y = _zoom.Scale((float)startunit) + (float)_offset; y < this.Height; y += unitwidth, startunit += unit) { DrawYLines(e.Graphics, y, unitwidth, this.Width - 1, index + 1); e.Graphics.DrawString((-startunit).ToString(), this.Font, Brushes.Black, new RectangleF(0f, y, this.Width / 2, 60f), fmt); } } } using (SolidBrush brs = new SolidBrush(Color.FromArgb(127, 0, 0, 0))) { Rectangle rct = GetMarkerBounds(_value, _length); e.Graphics.FillRectangle(brs, rct); rct.Width--; rct.Height--; if (rct.Width > 1 && rct.Height > 1) { e.Graphics.DrawRectangle(Pens.White, rct); } } }