gpt4 book ai didi

delphi - 将滚动条隐藏在 Delphi dbgrid 中(即使在调整大小时)

转载 作者:行者123 更新时间:2023-12-03 14:43:48 27 4
gpt4 key购买 nike

对于我们的 dbgrid,我们希望滚动条始终隐藏。由于 TDBGrid 没有“滚动条”属性,我们使用:

ShowScrollBar(DBGrid1.Handle, SB_VERT, False);
ShowScrollBar(DBGrid1.Handle, SB_HORZ, False);

但是,当我们调整窗口(以及包含 dbgrid 的面板)的大小时,一秒钟滚动条出现,只有在调用后才再次隐藏以上两种方法。

解决方案是在DrawColumnCell中调用这些方法,但这会导致闪烁dbgrid 的值,即使 DoubleBuffered 设置为 true。

有什么办法可以永久隐藏滚动条吗?

提前致谢!

最佳答案

隐藏TDBGrid的滚动条在 CreateParams具有极短的时间效应。程序是UpdateScrollBar这会导致滚动条可见。发生这种情况是因为滚动条的可见性是根据显示的数据来控制的,因此每当数据更改时都会调用此过程。

由于每当需要更新滚动条时都会调用此过程,并且由于它是虚拟的,因此是时候覆盖它了。
以下代码示例使用插入类,因此所有 TDBGrid属于该单元的表单上的组件将表现相同:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TDBGrid = class(DBGrids.TDBGrid)
private
procedure UpdateScrollBar; override;
end;

type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TDBGrid.UpdateScrollBar;
begin
// in this procedure the scroll bar is being shown or hidden
// depending on data fetched; and since we never want to see
// it, do just nothing at all here
end;

end.

关于delphi - 将滚动条隐藏在 Delphi dbgrid 中(即使在调整大小时),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7529524/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com