During writing a custom control, while trying to implement the default BorderWidth
property correctly, I seem to have stumbled upon a bug in the painting behavi
The search results in QualityCentral on BorderWidth shows that this bug is not reported before. Bug QC 2433 (which was resolved in D2010, update 4) seems related, but from the comments I understand the bug in question does not exist in D2007.
Verification from the community here is more needed though.
Override the WM_NCPAINT
message handler:
private
procedure WMNCPaint(var Message: TWMNCPaint); message WM_NCPAINT;
procedure TForm1.WMNCPaint(var Message: TWMNCPaint);
{$IF CompilerVersion < 19}
var
DC: HDC;
WindowStyle: Longint;
TotalBorderWidth: Integer;
{$IFEND}
begin
{$IF CompilerVersion < 19}
DC := GetWindowDC(Handle);
try
WindowStyle := GetWindowLong(Handle, GWL_STYLE);
if WindowStyle and WS_VSCROLL <> 0 then
TotalBorderWidth := (Width - ClientWidth - GetSystemMetrics(SM_CXVSCROLL)) div 2
else
TotalBorderWidth := (Width - ClientWidth) div 2;
if WindowStyle and WS_HSCROLL <> 0 then
FillRect(DC, Rect(0, Height - TotalBorderWidth, Width, Height), Brush.Handle);
if WindowStyle and WS_VSCROLL <> 0 then
FillRect(DC, Rect(Width - TotalBorderWidth, 0, Width, Height), Brush.Handle);
finally
ReleaseDC(Handle, DC);
end;
{$IFEND}
inherited;
end;
The two drawn rects are intentionally too large, giving better results at resizing.