delphi – BorderWidth的错误修正> 0与滚动条组合?

前端之家收集整理的这篇文章主要介绍了delphi – BorderWidth的错误修正> 0与滚动条组合?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在编写自定义控件时,在尝试正确实现默认的BorderWidth属性时,我似乎偶然发现了滚动条显示时绘画行为中的错误:滚动条和控件范围之间的空格未绘制.

要重现该错误,请为新项目的主窗体实现以下OnCreate处理程序:

procedure TForm1.FormCreate(Sender: TObject);
begin
  AutoScroll := True;
  BorderWidth := 20;
  SetBounds(10,10,200,200);
  with TGroupBox.Create(Self) do
  begin
    SetBounds(300,300,50,50);
    Parent := Self;
  end;
end;

D7和XE2的结果:

这似乎在Delphi XE2中得到了解决.可能,这个bug会驻留在TWinControl.WMNCPaint中,但是看看Controls.pas,我发现D7和XE2之间的实现没有任何显着差异.

我想得到答案:

>如何编写这个奇怪的错误修正,
>从哪个Delphi版本这个bug似乎得到修复.

解决方法

从哪个Delphi版本修复?

BorderWidth上的QualityCentral中的search results显示之前未报告此错误.错误QC 2433(已在D2010中解决,更新4)似乎相关,但从评论中我了解到有问题的错误在D2007中不存在.

但是,更需要来自社区的验证.

如何修复版本< D2007? 覆盖WM_NCPAINT消息处理程序:

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,Brush.Handle);
  finally
    ReleaseDC(Handle,DC);
  end;
{$IFEND}
  inherited;
end;

两个绘制的rects有意太大,在调整大小时给出了更好的结果.

猜你在找的Delphi相关文章