将滚动条隐藏在Delphi dbgrid中(即使在调整大小) [英] Keep the scrollbars hidden in a Delphi dbgrid (even on resize)
问题描述
对于我们的dbgrid,我们希望滚动条不断被隐藏。
由于TDBGrid没有scrollbars属性,我们使用:
For our dbgrid we want the scrollbars to be constantly hidden. Since TDBGrid doesn't have a 'scrollbars' property, we use:
ShowScrollBar(DBGrid1.Handle, SB_VERT, False);
ShowScrollBar(DBGrid1.Handle, SB_HORZ, False);
然而,当我们调整窗口大小(和包含dbgrid的面板)时,
a在上述两种方法调用
之后,滚动条就会再次出现,并且再次被隐藏。
However when we resize the window (and the panel containing the dbgrid), for a second the scrollbars appear and becom hidden again only after recalling the two above methods.
解决方案是在DrawColumnCell中调用这些方法,但这会导致闪烁
的dbgrid,即使DoubleBuffered设置为true。
A solution is to call these methods in DrawColumnCell, but this causes flickering of the dbgrid, even with DoubleBuffered set to true.
有没有办法永久隐藏滚动条?
Is there any way to hide the scrollbars permanently?
提前感谢
推荐答案
隐藏 TDBGrid
在 CreateParams
具有非常短的时间效应。有程序 UpdateScrollBar
其中导致滚动条可见。这是因为滚动条可见性是根据显示的数据进行控制的,因此每当数据更改时都会调用此过程。
Hiding the scrollbar of the TDBGrid
in CreateParams
has a very short time effect. There's the procedure UpdateScrollBar
which causes the scrollbar to be visible. It happens because the scroll bar visibility is controlled depending on the data displayed, thus this procedure is called whenever the data is changed.
由于此过程在滚动条时被调用需要更新,因为它是虚拟的,现在是覆盖它的时间。
以下代码示例使用了插入的类,所以 TDBGrid
组件在该单元上的表单将表现相同:
And since this procedure is called whenever the scrollbar needs to be updated and because it's virtual, it's time to override it.
The following code sample uses the interposed class, so all TDBGrid
components on the form which belongs to this unit will behave the same:
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 dbgrid中(即使在调整大小)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!