DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: liangjiping168
今日帖子: 16
在线用户: 10
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2021/12/4 15:11:58
标题:
My CardPanel using just THeaderControl + TPanel simulating by Emailx45 浏览:1081
加入我的收藏
楼主: My CardPanel simulating...
by Emailx45

unit uView.FormMain;

interface

uses
  Winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.Variants,
  System.Classes,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs,
  Vcl.ComCtrls,
  Vcl.ExtCtrls,
  Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    PnlMyCardPanel: TPanel;
    HeaderControl1: THeaderControl;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure HeaderControl1SectionClick(HeaderControl: THeaderControl; Section: THeaderSection);
  private
    MyCards          : array of TPanel;
    CurrentCardOnPanel: integer;
    AtomicIndexToNames: integer;
    //
    procedure CreateNewCard(AIndex: integer);
    procedure MyCardNames;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  System.Generics.Collections,
  System.Generics.Defaults;

procedure TForm1.CreateNewCard(AIndex: integer);
begin
  inc(AtomicIndexToNames);  // FIX TO PANEL-NAMES
  //
  MyCards[AIndex]          := TPanel.Create(PnlMyCardPanel);
  MyCards[AIndex].Name      := 'Panel' + AtomicIndexToNames.ToString;
  MyCards[AIndex].Visible   := false;
  MyCards[AIndex].Font.Size := 30;
  MyCards[AIndex].Caption   := 'Panel' + AtomicIndexToNames.ToString;
  MyCards[AIndex].Left      := 0;
  MyCards[AIndex].Top       := 0;
  MyCards[AIndex].Parent    := PnlMyCardPanel;
  MyCards[AIndex].Align     := TAlign.alClient;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
begin
  HeaderControl1.Sections.Items[2].Width := HeaderControl1.Width - { }
    (HeaderControl1.Sections.Items[0].Width + HeaderControl1.Sections.Items[1].Width + HeaderControl1.Sections.Items[3].Width + HeaderControl1.Sections.Items[4].Width);
  //
  SetLength(MyCards, 5);
  //
  for i := low(MyCards) to high(MyCards) do
    CreateNewCard(i);
  //
  CurrentCardOnPanel          := 0;
  MyCards[CurrentCardOnPanel].Visible := true;
end;

procedure TForm1.HeaderControl1SectionClick(HeaderControl: THeaderControl; Section: THeaderSection);
var
  a, b: TPanel;
begin
  case Section.ID of
    0:
      begin
        begin
          if (Length(MyCards) > 0) then
          begin
          if CurrentCardOnPanel <= high(MyCards) then
          begin
          MyCards[CurrentCardOnPanel].Visible := false;
          //
          MyCards[CurrentCardOnPanel].Free;
          Delete(MyCards, CurrentCardOnPanel, 1);
          end;
          //
          if Length(MyCards) > 0 then
          begin
          if CurrentCardOnPanel <= high(MyCards) then
          MyCards[CurrentCardOnPanel].Visible := true
          else
          begin
          if (CurrentCardOnPanel + 1) <= high(MyCards) then
          begin
          inc(CurrentCardOnPanel);
          MyCards[CurrentCardOnPanel].Visible := true;
          end
          else
          begin
          CurrentCardOnPanel          := high(MyCards);
          MyCards[CurrentCardOnPanel].Visible := true;
          end;
          end;
          end;
          end;
        end;
      end;
    1:
      begin
        if ((CurrentCardOnPanel - 1) >= 0) then
        begin
          MyCards[CurrentCardOnPanel].Visible := false;
          dec(CurrentCardOnPanel);
          MyCards[CurrentCardOnPanel].Visible := true;
        end;
      end;
    2:
      MyCardNames;
    3:
      begin
        if ((CurrentCardOnPanel + 1) < Length(MyCards)) then
        begin
          MyCards[CurrentCardOnPanel].Visible := false;
          inc(CurrentCardOnPanel);
          MyCards[CurrentCardOnPanel].Visible := true;
        end;
      end;
    4:
      begin
        SetLength(MyCards, Length(MyCards) + 1);
        //
        CreateNewCard(high(MyCards));
        //
        CurrentCardOnPanel          := high(MyCards);
        MyCards[CurrentCardOnPanel].Visible := true;
      end;
  end;
end;

procedure TForm1.MyCardNames;
begin
  Memo1.Lines.Clear;
  //
  for var MyCard in MyCards do
    Memo1.Lines.Add('Card name=[' + MyCard.Name + '] Tag=' + MyCard.Tag.ToString);
end;

(* procedure TForm1.OrganizeCardsByCardTag;
  begin
  TArray.Sort<TPanel>(MyCards, TDelegatedComparer<TPanel>.Construct(
  function(const Left, Right: TPanel): integer
  begin
  Result := TComparer<integer>.Default.Compare(Left.Tag, Right.Tag);
  end));
  end; *)

end.
此帖子包含附件:
PNG 图像
大小:117.5K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 luckyso999 (luckyso) ★☆☆☆☆ -
盒子活跃会员
2021/12/8 10:18:34
1楼: 按此在新窗口浏览图片
强大
----------------------------------------------
-
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行82.03125毫秒 RSS