Bugfix for BorderWidth > 0 in combination with a scroll bar?

后端 未结 1 2034
独厮守ぢ
独厮守ぢ 2020-12-19 12:14

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

1条回答
  •  隐瞒了意图╮
    2020-12-19 12:35

    From which Delphi version fixed?

    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.

    How to fix for versions < D2007?

    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.

    0 讨论(0)
提交回复
热议问题