It may seem simple to use DrawFocusRect
, but if you need to draw something else than rectangles, you may want to read ahead.
The pen style psDot
does not mean that every second pixel is colored and the other cleared. If you think about it, the higher the resolution the harder it would be to see the difference of dotted vs. gray solid f.ex. There is another pen style psAlternate
which alternates the pixels. The docs say:
psAlternate
The pen sets every other pixel. (This style is applicable only for
cosmetic pens.) This style is only valid for pens created with the
ExtCreatePen API function. (See MS Windows SDK docs.) This applies to
both VCL and VCL.NET.
To define the pen and use it we do as follows
var
c: TCanvas;
oldpenh, newpenh: HPEN; // pen handles
lbrush: TLogBrush; // logical brush
...
c := pbx.Canvas; // pbx is a TPintBox, but can be anything with a canvas
lbrush.lbStyle := BS_SOLID;
lbrush.lbColor := clBlack;
lbrush.lbHatch := 0;
// create the pen
newpenh := ExtCreatePen(PS_COSMETIC or PS_ALTERNATE, 1, lbrush, 0, nil);
try
// select it
oldpenh := SelectObject(c.Handle, newpenh);
// use the pen
c.MoveTo(0, 0);
c.LineTo(0, pbx.Height - 1);
c.LineTo(pbx.Width - 1, pbx.Height - 1);
c.LineTo(pbx.Width - 1, 0);
c.LineTo(0, 0);
c.Ellipse(3, 3, pbx.width-3, pbx.Height-3);
// revert to the old pen
SelectObject(c.Handle, oldpenh);
finally
// delete the pen
DeleteObject(newpenh);
end;
And finally what it looks like (the magnifier is at x 10)
