Dai*_*tsu 5 delphi ownerdrawn tstringgrid stringgrid
我试图隐藏 Delphi 在 StringGrid 中当前选定的单元格周围绘制的边框(焦点矩形)。我正在做所有者绘图来自定义字符串网格的外观。我已经成功地摆脱了除了选择之外的所有内容。
我正在使用
GR.Left := -1;
GR.Top := -1;
GR.Right := -1;
GR.Bottom := -1;
StringGrid.Selection := GR;
Run Code Online (Sandbox Code Playgroud)
但如果你设置得非常快,就会出现错误(我在 onMouseMove 中运行它)。我的意思是它工作得很好,但是如果我足够快地调用这个特定的代码块,我会在 StringGrid 的渲染中遇到异常(因此我不能只是放弃尝试,除了它周围)。
关于如何可靠地解决这个问题有什么想法吗?
您可以使用 TStringgrid 的插入器类并覆盖 Paint 过程以删除绘制的焦点矩形。
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TStringgrid=Class(Grids.TStringGrid)
private
FHideFocusRect: Boolean;
protected
Procedure Paint;override;
public
Property HideFocusRect:Boolean Read FHideFocusRect Write FHideFocusRect;
End;
TForm2 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TStringgrid.Paint;
var
L_Rect:Trect;
begin
inherited;
if HideFocusRect then
begin
L_Rect := CellRect(Col,Row);
if DrawingStyle = gdsThemed then InflateRect(L_Rect,-1,-1);
DrawFocusrect(Canvas.Handle,L_Rect)
end;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
StringGrid1.HideFocusRect := not StringGrid1.HideFocusRect;
end;
end.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7170 次 |
| 最近记录: |