C++ Builder XE4, 10.2 Tokyo > TPageControl + TFrame > TButton에서 페이지(TFrame) 추가

12931 단어 TPageControlcppBuilder
운영 환경
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2018/01/05)

TPageControl에 TFrame 페이지를 추가하고 싶습니다.

구성


  • Unit1(TForm)
  • TPageControl을 가지는

  • Unit2(TFrame)
  • TLabel로
  • TTimer를 가진


  • Unit2의 디자인은 이하.


    참고



    papy 님의 언어 게시판
    h tp // w w. Papy. in / bs / lp / 200906/09060057. HTML

    정보 감사입니다.

    코드



    Unit2.h
    //---------------------------------------------------------------------------
    
    #ifndef Unit2H
    #define Unit2H
    //---------------------------------------------------------------------------
    #include <System.Classes.hpp>
    #include <Vcl.Controls.hpp>
    #include <Vcl.StdCtrls.hpp>
    #include <Vcl.Forms.hpp>
    #include <Vcl.ExtCtrls.hpp>
    //---------------------------------------------------------------------------
    class TFrame2 : public TFrame
    {
    __published:    // IDE で管理されるコンポーネント
        TLabel *Label1;
        TTimer *Timer1;
        void __fastcall Timer1Timer(TObject *Sender);
    private:    // ユーザー宣言
    public:     // ユーザー宣言
        __fastcall TFrame2(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TFrame2 *Frame2;
    //---------------------------------------------------------------------------
    #endif
    

    Unit2.cpp
    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    
    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TFrame2 *Frame2;
    //---------------------------------------------------------------------------
    __fastcall TFrame2::TFrame2(TComponent* Owner)
        : TFrame(Owner)
    {
        Timer1->Enabled = false;
        Timer1->Interval = 5000; // msec
        Timer1->Enabled = true;
    }
    //---------------------------------------------------------------------------
    void __fastcall TFrame2::Timer1Timer(TObject *Sender)
    {
        String msg = Now().FormatString(L"yyyy/mm/dd hh:nn:ss");
        OutputDebugString(msg.c_str());
    }
    //---------------------------------------------------------------------------
    

    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"
    #include "Unit2.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);
    
        TFrame2 *pFrame = new TFrame2(pPage);
        pFrame->Parent = pPage;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::B_deleteClick(TObject *Sender)
    {
        int count = PageControl1->PageCount;
    
        if (count == 0) {
            return;
        }
    
        delete PageControl1->Pages[count - 1];
    }
    //---------------------------------------------------------------------------
    

    실행



    페이지를 늘리면 디버그 출력이 늘어납니다.
    デバッグ出力: 2017/11/01 19:00:18 プロセス Project1.exe (2240)
    デバッグ出力: 2017/11/01 19:00:19 プロセス Project1.exe (2240)
    デバッグ出力: 2017/11/01 19:00:20 プロセス Project1.exe (2240)
    デバッグ出力: 2017/11/01 19:00:21 プロセス Project1.exe (2240)
    デバッグ出力: 2017/11/01 19:00:21 プロセス Project1.exe (2240)
    デバッグ出力: 2017/11/01 19:00:22 プロセス Project1.exe (2240)
    デバッグ出力: 2017/11/01 19:00:22 プロセス Project1.exe (2240)
    デバッグ出力: 2017/11/01 19:00:23 プロセス Project1.exe (2240)
    デバッグ出力: 2017/11/01 19:00:23 プロセス Project1.exe (2240)
    

    좋은 웹페이지 즐겨찾기