toolbar上边动态生成100个按钮,如果用两个按钮来翻页?解决办法
toolbar上边动态生成100个按钮,如果用两个按钮来翻页?
toolbar有100个动态生成的按钮(SpeedButton),我想用两个按钮做成滚动条的效果,点一次显示8个按钮
------解决方案--------------------
直接放100个,或者panel上放100个
2个按钮去控制容器toolbar或panel的可见部分的x方向位置
------解决方案--------------------
你应该是需要拖一个 TPageScroller 作为 toolbar 的 parent
------解决方案--------------------
新建工程、双击工程中的窗体、用下列代码覆盖你的unit1所有内容:
toolbar有100个动态生成的按钮(SpeedButton),我想用两个按钮做成滚动条的效果,点一次显示8个按钮
------解决方案--------------------
直接放100个,或者panel上放100个
2个按钮去控制容器toolbar或panel的可见部分的x方向位置
------解决方案--------------------
你应该是需要拖一个 TPageScroller 作为 toolbar 的 parent
------解决方案--------------------
新建工程、双击工程中的窗体、用下列代码覆盖你的unit1所有内容:
- Delphi(Pascal) code
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ToolWin, ComCtrls, ImgList, StdCtrls, Buttons; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure ButtonClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation var ToolBar:TToolBar; ToolButton:array[0..99]of TToolButton; Button:array[0..1]of TButton; btindex:integer; {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var i:integer; begin Width:=623; Height:=250; Position:=poScreenCenter; OnCloseQuery:=FormCloseQuery; ToolBar:=TToolBar.Create(self); ToolBar.Parent:=Form1; ToolBar.Wrapable:=false; ToolBar.Height:=44; // ToolBar.Images:=ImageList1; //假如你有这个组件在,则去除注释 ToolBar.ShowCaptions:=true; for i:=99 downto 0 do begin ToolButton[i]:=TToolButton.Create(self); ToolButton[i].ImageIndex:=i; ToolButton[i].Parent:=ToolBar; ToolButton[i].AutoSize:=false; ToolButton[i].Width:=80; ToolButton[i].Caption:='ToolButton'+inttostr(i+1); end; for i:=8 to 99 do ToolButton[i].Visible:=false; for i:=0 to 1 do begin Button[i]:=TButton.Create(self); Button[i].Parent:=Form1; Button[i].Top:=140; Button[i].Left:=i*Button[i].Width+100*i+190; Button[i].OnClick:=ButtonClick; end; Button[0].Caption:='上一组'; Button[0].Enabled:=false; Button[1].Caption:='下一组'; end; procedure TForm1.ButtonClick(Sender: TObject); var i:integer; begin if TButton(Sender).Caption='下一组' then begin Button[0].Enabled:=true; if btindex<12 then inc(btindex); if btindex=12 then Button[1].Enabled:=false; end else begin Button[1].Enabled:=true; if btindex>0 then dec(btindex); if btindex=0 then Button[0].Enabled:=false; end; for i:=0 to 99 do begin if i in [btindex*8..btindex*8+7]then ToolButton[i].Visible:=true else ToolButton[i].Visible:=false; end; end; procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); var i:integer; begin ToolBar.Free; for i:=0 to 1 do Button[i].Free; end; end.