如何处理TScrollBox的鼠标滚轮事件?

cool_afei 2004-11-18 10:20:44
如题,麻烦给个例子,行吗?
...全文
185 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dext 2004-11-18
  • 打赏
  • 举报
回复
第二个方法简单,第一个方法通用!

方法二:
TForm1 = class(TForm)
procedure OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);
end;

procedure TForm1.OnMouseWheel(Var Msg :TMsg;var Handled:Boolean);
begin
if Msg.message = WM_MouseWheel then
begin
if Msg.wParam > 0 then
begin
SendMessage(ScrollBox1.Handle,wm_VScroll,sb_LineUp,0);
end
else
begin
SendMessage(ScrollBox1.Handle,wm_VScroll,sb_LineDown,0);
end;
Handled:= True;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage:=OnMouseWheel;
end;

方法一:


type
TScrollBox1 = class(TScrollBox)
procedure OnMouseWheel(Var Msg: TMsg); message WM_MouseWheel;
....
end;


你试试吧,我手头没有Delphi!

dext 2004-11-18
  • 打赏
  • 举报
回复
Delphi7 里ScrollBox本身有MouseWheel事件
Delphi7一下,有两个方法!
一个是继承TScrollBox,重写WndProc
第二个使用Apllication.OnMessage;

fbysss 2004-11-18
  • 打赏
  • 举报
回复
procedure TForm1.ScrollBox1MouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position - WheelDelta;
end;
fbysss 2004-11-18
  • 打赏
  • 举报
回复
ScrollBox本身有MouseWheel事件,在这里写入处理代码即可
DELPHI动态创建删除FRAME unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,FM; type TForm2 = class(TForm) Panel1: TPanel; Button2: TButton; ScrollBox1: TScrollBox; procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; type TFM = Array Of TFrame1; var Form2: TForm2; aFM: TFM; procedure DeleteArrItem(var arr: TFM ; Index: Integer);stdcall; implementation {$R *.dfm} procedure DeleteArrItem(var arr: TFM ; Index: Integer); var Count: Cardinal; i:integer; begin Count := Length(arr); if (Count = 0) or (Index = Count) then Exit; Move(arr[Index+1], arr[Index], (Count-Index)* SizeOf(arr[0])); SetLength(arr, Count - 1); for I := 0 to Length(arr) - 1 do begin arr[i].Label1.Caption:=inttostr(i); end; end; procedure TForm2.Button2Click(Sender: TObject); var fram:TFrame1; begin SetLength(aFM,length(aFM)+1); aFM[length(aFM)-1] :=TFrame1.Create(nil) ; fram:=aFM[length(aFM)-1]; fram.Label1.Caption:=inttostr(length(aFM)-1); fram.Parent:=ScrollBox1; end; end. unit fm; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TFrame1 = class(TFrame) GroupBox1: TGroupBox; Label1: TLabel; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; implementation uses unit2; {$R *.dfm} procedure TFrame1.Button1Click(Sender: TObject); begin DeleteArrItem(aFM,strtoint(label1.Caption)); ( Sender as Tbutton ).Parent.Parent.Destroy; end; end.

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧