Tracer
Tracer

Reputation: 2736

How to change DrawFocusRect pen width?

I'm using C++ Builder and trying to use DrawFocusRect function:

DrawRect.left = X;
DrawRect.top = Y;
DrawRect.right = X;
DrawRect.bottom = Y;
Canvas->DrawFocusRect(DrawRect);

The problem is that this rectangle is barely visible. I tried this:

Canvas->Pen->Width = 2;

But no success. Is it possible to change the width of focus rectangle or is there some other approach I could use?

Upvotes: 0

Views: 1154

Answers (1)

David Heffernan
David Heffernan

Reputation: 613481

This method maps to the Windows API function DrawFocusRect. The documentation for which says:

Windows XP: The focus rectangle can now be thicker than 1 pixel, so it is more visible for high-resolution, high-density displays and accessibility needs. This is handled by the SPI_SETFOCUSBORDERWIDTH and SPI_SETFOCUSBORDERHEIGHT in SystemParametersInfo.

So you can indeed control the width. However, the modification you make applies to all programs on the current desktop. Which I am pretty sure is not what you desire. So my recommendation is that you do not use DrawFocusRect and instead draw this rectangle manually. It is very easy to do. It is just alternating black and white pixels and can be draw efficiently with BitBlt. And quite possibly other simpler ways.

Upvotes: 1

Related Questions