Delphi dbgrid continuous scrolling

a 夏天 提交于 2019-12-21 04:54:08

问题


I'm making an application that holds orders and prints invoices. I have some labels, tedits, tmemos, buttons, a datasource, an adotable, a popupmenu, and a dbgrid on my form.

When I build the program and scroll down the dbgrid scrollbar, it scrolls after I release mouse button. But i want continuous scrolling.

Greetings


回答1:


That's called thumb tracking. Derive a new class to override scrolling behavior. Example of using an interposer class:

type
  TDBGrid = class(DBGrids.TDBGrid)
  private
    procedure WmVScroll(var Message: TWMVScroll); message WM_VSCROLL;
  end;

  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    ..

implementation

procedure TDBGrid.WmVScroll(var Message: TWMVScroll);
begin
  if Message.ScrollCode = SB_THUMBTRACK then
    Message.ScrollCode := SB_THUMBPOSITION;
  inherited;
end;


You can also replace the WindowProc of the control if you don't want to derive a new class. All you need to do is to handle WM_VSCROLL message. Here is an example how to do that.




回答2:


Here is the other solution Sertac Akyuz mentioned without having to derive a new class from TDBGrid:

  private
    FOrgDBGridWndProc: TWndMethod;
    procedure DBGridWndProc(var Msg: TMessage);
  // ...
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FOrgDBGridWndProc:= DBGrid1.WindowProc;
  DBGrid1.WindowProc := DBGridWndProc;
end;

procedure TForm1.DBGridWndProc(var Msg: TMessage);
begin
  if (Msg.Msg = WM_VSCROLL) and
    (LongRec(Msg.wParam).Lo = SB_THUMBTRACK) then
  begin
      LongRec(Msg.wParam).Lo := SB_THUMBPOSITION;
  end;
  if Assigned(FOrgDBGridWndProc) then
    FOrgDBGridWndProc(Msg);
end;


来源:https://stackoverflow.com/questions/6918923/delphi-dbgrid-continuous-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!