void DrawText(Pen p, TickLoc loc, Graphics g) { // The sizing operation is common to all options StringFormat format = new StringFormat(StringFormatFlags.MeasureTrailingSpaces); if (IsVertical) { format.FormatFlags |= StringFormatFlags.DirectionVertical; } SizeF size = g.MeasureString((loc.val).ToString(), this.Font, loc.spaceAvailable, format); Point drawingPoint; int iX = 0; int iY = 0; if (drawPannel.IsHandleCreated) { if (!Invert) { iX = loc.pos + loc.spaceAvailable - (int)size.Width - 2; iY = 2; } else { iX = loc.pos + loc.spaceAvailable - (int)size.Width - 2; iY = drawPannel.Height - 2 - (int)size.Height; } drawingPoint = new Point(iX, iY); } else { if (!Invert) { iX = 2; iY = loc.pos + loc.spaceAvailable - (int)size.Height - 2; } else { iX = Width - 2 - (int)size.Width; iY = loc.pos + loc.spaceAvailable - (int)size.Height - 2; } drawingPoint = new Point(iX, iY); } // The drawstring function is common to all operations g.DrawString(loc.val.ToString(), this.Font, new SolidBrush(this.ForeColor), drawingPoint, format); }
void DrawLoc(Pen p, TickLoc loc, Graphics g) { int length = Convert.ToInt32((IsVertical ? drawPannel.Width : drawPannel.Height) * (loc.isMajor ? MajorTickHeightPrecentage : MinorTickHeightPrecentage)); int startAt = Invert ? 0 : (IsVertical ? drawPannel.Width : drawPannel.Height); int endAt = Invert ? length : (IsVertical ? drawPannel.Width - length : drawPannel.Height - length); Point start = IsVertical ? new Point(startAt, loc.pos) : new Point(loc.pos, startAt); Point end = IsVertical ? new Point(endAt, loc.pos) : new Point(loc.pos, endAt); g.DrawLine(p, start, end); }