C++ Builder XE4, 10.2 Tokyo > TPageControl > TButtonでのページの追加、削除
7387 ワード
動作環境
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2018/01/05)
TPageControlのページを動的に変更してみる。
参考: https://stackoverflow.com/questions/21970127/delete-tabs-from-a-page-control-at-run-time
Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ComCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE で管理されるコンポーネント
TPageControl *PageControl1;
TButton *B_add;
TButton *B_delete;
void __fastcall B_addClick(TObject *Sender);
void __fastcall B_deleteClick(TObject *Sender);
private: // ユーザー宣言
public: // ユーザー宣言
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::B_addClick(TObject *Sender)
{
int count = PageControl1->PageCount;
TTabSheet *pPage = new TTabSheet(PageControl1);
pPage->PageControl = PageControl1;
pPage->Caption = L"Page" + IntToStr(count);
pPage->Name = L"ts" + IntToStr(count);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::B_deleteClick(TObject *Sender)
{
int count = PageControl1->PageCount;
if (count == 0) {
return;
}
delete PageControl1->Pages[count - 1];
}
//---------------------------------------------------------------------------
Author And Source
この問題について(C++ Builder XE4, 10.2 Tokyo > TPageControl > TButtonでのページの追加、削除), 我々は、より多くの情報をここで見つけました https://qiita.com/7of9/items/7419400486a59f949e83著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .