代码如下:
unit AddMsgDBGrid;
interface
uses
windows, SysUtils, Messages, Classes, Controls, Grids, DBGrids;
type
TAddMsgDBGrid = class(TDBGrid)
protected //添加新的'鼠标滚轮消息'
procedure WMMOUSEWHEEL(var Message: TMessage); message WM_MOUSEWHEEL;
procedure Paint; override; //覆盖Paint是为了去除'水平滚动条'
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('GenCheng', [TAddMsgDBGrid]);
end;
{ TAddMsgDBGrid }
procedure TAddMsgDBGrid.WMMOUSEWHEEL(var Message: TMessage);
var
ScrollDown: Boolean;
begin
ScrollDown := Short(Message.WParamHi) < 0; //Short函数在windows单元
if assigned(self.DataSource) and assigned(self.DataSource.DataSet) and self.DataSource.DataSet.active then
if ScrollDown then
self.DataSource.DataSet.MoveBy(1) //或者Self.DataSource.DataSet.Next;
else
self.DataSource.DataSet.MoveBy(-1); //或者Self.DataSource.DataSet.Prior;
end;
procedure TAddMsgDBGrid.Paint;
begin
SetScrollRange(self.Handle, SB_HORZ, 0, 0, False); //去除水平滚动条
inherited Paint;
end;
end.