保持滚动条隐藏在Delphi dbgrid中(即使在调整大小时)

use*_*103 8 delphi c++builder scrollbar dbgrid c++builder-xe

对于我们的dbgrid,我们希望不断隐藏滚动条.由于TDBGrid没有'滚动条'属性,我们使用:

ShowScrollBar(DBGrid1.Handle, SB_VERT, False);
ShowScrollBar(DBGrid1.Handle, SB_HORZ, False);
Run Code Online (Sandbox Code Playgroud)

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

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

有没有办法永久隐藏滚动条?

提前致谢!

TLa*_*ama 6

隐藏TDBGridin 的滚动条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.
Run Code Online (Sandbox Code Playgroud)

  • 这就是所谓的insterposed类,如果你把它放到你的单元中就足够了(参见更新),它将覆盖你放入它的命名空间中的原始类(所以表单上的所有TDBGrid组件都属于单位将*子类*那样). (2认同)