[求助]怎么获得tScrollBox滚动条事件

lyzoyu 2009-08-19 08:08:13
我的窗口上有两个ScrollBox,希望在滚动一个scrollbox的时候另外一个也跟着滚动,这该怎么实现呢
...全文
326 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
CACACACACA 2009-08-19
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 lyzoyu 的回复:]
还有误,鼠标拖动一个scrollbox的滚动条时,另一个scrollbox的滚动条也跟着滚动
[/Quote]

我的代码就是"scrollbox的滚动条时,另一个scrollbox的滚动条也跟着滚动"啊!
有什么问题?
lyzoyu 2009-08-19
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 lihuimin622 的回复:]
简单一点 在ScrollBar1Change里写一句话就OK

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
  ScrollBar2.Position := ScrollBar1.Position;
end;
[/Quote]
tscrollbox没有Bar的change动作
lihuimin622 2009-08-19
  • 打赏
  • 举报
回复
简单一点 在ScrollBar1Change里写一句话就OK

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
ScrollBar2.Position := ScrollBar1.Position;
end;
lyzoyu 2009-08-19
  • 打赏
  • 举报
回复
还有误,鼠标拖动一个scrollbox的滚动条时,另一个scrollbox的滚动条也跟着滚动
lyzoyu 2009-08-19
  • 打赏
  • 举报
回复
额表达有误,鼠标拖动滚动条的同时,另一个窗口也跟着滚动
CACACACACA 2009-08-19
  • 打赏
  • 举报
回复
加行代码

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Self.ScrollBox1.WindowProc := Self.FOldWndProc;
end;
CACACACACA 2009-08-19
  • 打赏
  • 举报
回复

object Form1: TForm1
Left = 192
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object ScrollBox1: TScrollBox
Left = 80
Top = 80
Width = 249
Height = 225
TabOrder = 0
object BitBtn1: TBitBtn
Left = 72
Top = 80
Width = 75
Height = 25
Caption = 'BitBtn1'
TabOrder = 0
end
object StringGrid1: TStringGrid
Left = 32
Top = 128
Width = 320
Height = 120
TabOrder = 1
end
end
object ScrollBox2: TScrollBox
Left = 368
Top = 80
Width = 249
Height = 225
TabOrder = 1
object BitBtn2: TBitBtn
Left = 72
Top = 80
Width = 75
Height = 25
Caption = 'BitBtn1'
TabOrder = 0
end
object StringGrid2: TStringGrid
Left = 32
Top = 128
Width = 320
Height = 120
TabOrder = 1
end
end
object ApplicationEvents1: TApplicationEvents
Left = 32
Top = 120
end
end
CACACACACA 2009-08-19
  • 打赏
  • 举报
回复

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AppEvnts, Grids, StdCtrls, Buttons;

type
TForm1 = class(TForm)
ScrollBox1: TScrollBox;
BitBtn1: TBitBtn;
StringGrid1: TStringGrid;
ScrollBox2: TScrollBox;
BitBtn2: TBitBtn;
StringGrid2: TStringGrid;
ApplicationEvents1: TApplicationEvents;
procedure FormCreate(Sender: TObject);
private
FOldWndProc: TWndMethod;
public
procedure NewWndProc(var Msg: TMessage);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Self.FOldWndProc := Self.ScrollBox1.WindowProc;
Self.ScrollBox1.WindowProc := Self.NewWndProc;
end;

procedure TForm1.NewWndProc(var Msg: TMessage);
begin
if (Msg.Msg=WM_VSCROLL) or (Msg.Msg=WM_HSCROLL) then
if TWMVScroll(Msg).ScrollBar=0 then
Self.ScrollBox2.WindowProc(Msg);
Self.FOldWndProc(Msg);
end;

end.
yao1897 2009-08-19
  • 打赏
  • 举报
回复
试试一个ScrollBox的OnMouseWheel()事件里调用另一个的OnMouseWheel()事件
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.

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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