在 DBGrid 中如何判断鼠标对滚动条的操作?(80分)

  • 主题发起人 主题发起人 mblk
  • 开始时间 开始时间
M

mblk

Unregistered / Unconfirmed
GUEST, unregistred user!
在 DBGrid 中如何判断鼠标移动了滚动条上的游标?如何判断鼠标单击了滚动条上的箭头?
 
不知你想达到什么目的
 
你的需求挺古怪,为什么要这样呢?不过通过判断鼠标点击的范围行不行.
 
你可以在与 DBGRID 相联的 DataSet 的 Afterscroll 事件中加入 一发送自定义消息让
DBGRID 所在的窗体接收,即可以判断鼠标是否移动了滚动条上的游标
 
请给出原代码, 好吗?
 
Const
MyMsg_DataIsScroll=WM_USER+1;

//DataModal
procedure Tinvoi_dm.invoim_adsAfterScroll(DataSet: TDataSet);
begin
if frm_invoi=nil then exit;
postmessage(frm_invoi.Handle,MyMsg_DataIsScroll,0,0);
end;

//Forms

unit frm_invoip;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;

type
Tfrm_invoi = class(TForm)
private
{ Private declarations }
procedure DataScroll(var message: tmessage)
message MyMsg_DataIsScroll;
public
{ Public declarations }
end;

var
frm_invoi: Tfrm_invoi;

implementation


{$R *.dfm}

procedure Tfrm_invoi.DataScroll(var message: tmessage);
begin
//your refresh code;
end;



 
请问Rody, 你的delphi是什么版本的? 如果是delphi5, uses Variants 好象通不过.
 
不好意思!我的是6.0,你将那个单元见风删除就可以了
 
Rody, 你好, 按你说的改为以下代码, 编译正确, 但还是没反应, 麻烦你再指点指点.

unit Unit1;

interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
StdCtrls, Db, DBTables, Grids, DBGrids,Dialogs;

Const
MyMsg_DataIsScroll=WM_USER+1;


type
TForm1 = class(TForm)
Button1: TButton;
DataSource1: TDataSource;
Table1: TTable;
DBGrid1: TDBGrid;
private
{ Private declarations }

procedure DataScroll(var message: tmessage)
message MyMsg_DataIsScroll;
public
{ Public declarations }
procedure invoim_adsAfterScroll(DataSet: TDataSet);

end;


//DataModal


var
Form1: TForm1;

implementation

{$R *.DFM}


procedure tform1.invoim_adsAfterScroll(DataSet: TDataSet);
begin
if form1=nil then exit;
postmessage(form1.Handle,MyMsg_DataIsScroll,0,0);
end;


procedure tform1.DataScroll(var message: tmessage);
begin
//your refresh code;
showmessage('fasdsdfsd');
end;

 
mblk:
我在代码中已注明消息触发要在数据集的 AFTERSCROLL 事件中撰写,
而不是在窗体的公用部份定义。
 
Rody, 你好, 以上代码只在垂直滚动条上有反应, 在水平滚动条上没反应, 帮我解决
这个问题好吗?
 
The WM_VSCROLL message is sent to a window
when a scroll event occurs in the window's standard
vertical scroll bar. This message is also sent to the owner of
a vertical scroll bar control when a scroll event occurs in the control.

The WM_HSCROLL message is sent to a window when a scroll e
vent occurs in the window's standard horizontal scroll bar.
This message is also sent to the owner of a horizontal scroll bar
control when a scroll event occurs in the control.

The WM_VSCROLLCLIPBOARD message is sent to the clipboard
owner by a clipboard viewer window when the clipboard contains
data in the CF_OWNERDISPLAY format and an event occurs in the clipboard
viewer's vertical scroll bar. The owner should scroll the clipboard image
and update the scroll bar values.

 
请用中文回答好吗?
 
后退
顶部