动态列表
动态列表
涂孟超 发表于4年前
动态列表
  • 发表于 4年前
  • 阅读 1
  • 收藏 0
  • 点赞 0
  • 评论 0

【腾讯云】新注册用户域名抢购1元起>>>   

本例效果图:



代码文件:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure btnClick(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  btnArr: array[0..3] of TButton;

procedure TForm1.btnClick(Sender: TObject);
var
  i,n: Integer;
begin
  n := TButton(Sender).Tag;
  for i := 0 to Length(btnArr) - 1 do
  begin
    if i>n then
      btnArr[i].Align := alBottom
    else 
      btnArr[i].Align := alTop;
  end;

  ListBox1.Items.Add(TButton(Sender).Caption); 
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  btnArr[0] := Button1;
  btnArr[1] := Button2;
  btnArr[2] := Button3;
  btnArr[3] := Button4;

  for i := 0 to Length(btnArr) - 1 do
  begin
    btnArr[i].OnClick := btnClick;
    btnArr[i].Tag := i;
  end;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  ShowMessage(ListBox1.Items[ListBox1.ItemIndex]);
end;

end.

 
 
 
 
 

 

 

  
窗体文件:
object Form1: TForm1
  Left = 366
  Top = 238
  Caption = 'Form1'
  ClientHeight = 206
  ClientWidth = 266
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesigned
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 145
    Height = 206
    Align = alLeft
    Caption = 'Panel1'
    TabOrder = 0
    object Button1: TButton
      Left = 1
      Top = 1
      Width = 143
      Height = 25
      Align = alTop
      Caption = 'Button1'
      TabOrder = 0
    end
    object Button2: TButton
      Left = 1
      Top = 130
      Width = 143
      Height = 25
      Align = alBottom
      Caption = 'Button2'
      TabOrder = 1
    end
    object Button3: TButton
      Left = 1
      Top = 155
      Width = 143
      Height = 25
      Align = alBottom
      Caption = 'Button3'
      TabOrder = 2
    end
    object Button4: TButton
      Left = 1
      Top = 180
      Width = 143
      Height = 25
      Align = alBottom
      Caption = 'Button4'
      TabOrder = 4
    end
    object ListBox1: TListBox
      Left = 1
      Top = 26
      Width = 143
      Height = 104
      Align = alClient
      ItemHeight = 13
      TabOrder = 3
      OnClick = ListBox1Click
    end
  end
end

 
 
 
 
 

 

 

  
  • 打赏
  • 点赞
  • 收藏
  • 分享
共有 人打赏支持
粉丝 12
博文 2004
码字总数 14107
×
涂孟超
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: