// TODO: Needs 'DrawSelectBox(…)` // We also need implementation strategy for drawing a select-box that can be applied to widgets universally. static public void DrawSelectBox(this Graphics graphics, Widget widget, FloatRect lim = null, Color?colour = null) { if (widget.Parent.MouseM == null || widget.Parent.MouseD == null) { return; } Func <Point, Point> p2c = widget.Parent.PointToClient; var state = graphics.Save(); graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; var c1 = colour ?? DefaultSelectBoxColour; var c2 = Color.FromArgb(64, c1); // with alpha // find the closest x FloatPoint p0 = p2c(widget.Parent.MouseD.Nearest(widget.Parent.MouseM)); FloatPoint p1 = p2c(widget.Parent.MouseD.Furthest(widget.Parent.MouseM)); FloatPoint pA = p0.Smallest(p1); FloatPoint pB = p0.Largest(p1); if (lim != null) { pA = pA.Limit(lim.Location, lim.BottomRight); pB = pB.Limit(lim.Location, lim.BottomRight); pB = pB - pA; } FloatRect rect = new FloatRect(pA, pB); using (var p = new Pen(c1, 1)) using (var b = new SolidBrush(c2)) { graphics.DrawRectangle(p, rect); graphics.FillRectangle(b, rect); } graphics.Restore(state); }