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也是如此.
有没有办法永久隐藏滚动条?
提前致谢!
隐藏TDBGrid
in 的滚动条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)