delphi – BorderWidth的错误修正> 0与滚动条组合?
发布时间:2020-12-15 04:13:33 所属栏目:大数据 来源:网络整理
导读:在编写自定义控件时,在尝试正确实现默认的BorderWidth属性时,我似乎偶然发现了滚动条显示时绘画行为中的错误:滚动条和控件范围之间的空格未绘制. 要重现该错误,请为新项目的主窗体实现以下OnCreate处理程序: procedure TForm1.FormCreate(Sender: TObject)
在编写自定义控件时,在尝试正确实现默认的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版本修复?
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有意太大,在调整大小时给出了更好的结果. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |