AlphaControls控件TsScrollBox的关联TListBox用法
AlphaControls 控件 TsScrollBox,与Delphi Additional页上TsScrollBox相似,提供水平、垂直滚行条的群组框部件,可用作在窗体中提供一个可以多方向滚行的工具。如果您只想显示较大幅面的一个部分,并允许您的用户对其进行滚行操作,ScrollBar将是理想的选择。您可以先在全幅面的滚动框中进行全面设计,然后适当地缩小外框,两个方向的滚行条将自动显示。它的Position属性是集成在HorzScrollBar和VertScrollBar两个集属性下的,编程时,可以选定这两个属性进行操作。
AlphaControls 控件 TsScrollBox更具灵活性,编程时,在scrollbox控件中放置一个panel,设置panel的Align属性为,取决于它有外形尺寸,当包含的内容大于外形时,滚动条就显示出来。
下面介绍一种TsScrollBox的关联TListBox用法:
见上图,点击 TsScrollBox时,ListBox联动,用户选择“机构名称”时,二者均可以使用。
一、定义一个TFrame,作为 TsScrollBox的包含内容
unit uFrame_FZ;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, sFrameAdapter, ImgList, acAlphaImageList, Buttons, sSpeedButton,
ShellAPI, inifiles;
type
TFrame_FZ = class(TFrame)
sSpeedButton1: TsSpeedButton;
sSpeedButton2: TsSpeedButton;
sFrameAdapter1: TsFrameAdapter;
sSpeedButton3: TsSpeedButton;
sSpeedButton4: TsSpeedButton;
sSpeedButton5: TsSpeedButton;
sSpeedButton6: TsSpeedButton;
sSpeedButton7: TsSpeedButton;
sSpeedButton8: TsSpeedButton;
sSpeedButton9: TsSpeedButton;
sSpeedButton10: TsSpeedButton;
sSpeedButton11: TsSpeedButton;
sSpeedButton12: TsSpeedButton;
sSpeedButton13: TsSpeedButton;
sSpeedButton14: TsSpeedButton;
sSpeedButton15: TsSpeedButton;
sSpeedButton16: TsSpeedButton;
sSpeedButton17: TsSpeedButton;
sSpeedButton18: TsSpeedButton;
sSpeedButton19: TsSpeedButton;
sSpeedButton20: TsSpeedButton;
procedure sSpeedButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
uses uMy_COM, uMy_COM1, uMainFrm;
{$R *.dfm}
procedure TFrame_FZ.sSpeedButton1Click(Sender: TObject);
var L:Integer;
begin
if TWinControl(Sender).Name='sSpeedButton1' then L:=0;
if TWinControl(Sender).Name='sSpeedButton2' then L:=1;
if TWinControl(Sender).Name='sSpeedButton3' then L:=2;
if TWinControl(Sender).Name='sSpeedButton4' then L:=3;
if TWinControl(Sender).Name='sSpeedButton5' then L:=4;
if TWinControl(Sender).Name='sSpeedButton6' then L:=5;
if TWinControl(Sender).Name='sSpeedButton7' then L:=6;
if TWinControl(Sender).Name='sSpeedButton8' then L:=7;
if TWinControl(Sender).Name='sSpeedButton9' then L:=8;
if TWinControl(Sender).Name='sSpeedButton10' then L:=9;
if TWinControl(Sender).Name='sSpeedButton11' then L:=10;
if TWinControl(Sender).Name='sSpeedButton12' then L:=11;
if TWinControl(Sender).Name='sSpeedButton13' then L:=12;
if TWinControl(Sender).Name='sSpeedButton14' then L:=13;
if TWinControl(Sender).Name='sSpeedButton15' then L:=14;
if TWinControl(Sender).Name='sSpeedButton16' then L:=15;
if TWinControl(Sender).Name='sSpeedButton17' then L:=16;
if TWinControl(Sender).Name='sSpeedButton18' then L:=17;
if TWinControl(Sender).Name='sSpeedButton19' then L:=18;
if TWinControl(Sender).Name='sSpeedButton20' then L:=19;
MainFrm.ListBox1.ItemIndex:=L;
MainFrm.ListBox1.OnClick(Sender); // 让ListBox1关联的按键联运
end;
end.
二、将TFrame加入TsScrollBox( OnShow事件)
Frame_FZ.Parent := sScrollBox1; // 加入容器
三、关联的ListBox1,定义OnCheck事件
procedure TMainFrm.ListBox1Click(Sender: TObject);
var k:Integer;
begin
K:=ListBox1.ItemIndex;
UsesName:=ListBox1.Items.Strings[k];
sFCID:=FCID_List.Strings[K];
Label13.Caption:=sFCID;
end;
四、定义TsScrollBox滚轮事件
procedure TMainfrm.sScrollBox1MouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
if WheelDelta<0 then
sScrollBox1.Perform(WM_VSCROLL,SB_LINEDOWN,0) //发送消息
else
sScrollBox1.Perform(WM_VSCROLL,SB_LINEUP,0);
end;