c++ builder XE4 > Form > 4개의 Form을 모니터 가득 정렬

동작 확인
C++ Builder XE4

4개의 TForm이 있는 앱.

그것을 다음과 같은 배열로 만들고 싶다.
  • Form1: 왼쪽 상단에 배치. 크기 H1 x W2
  • Form2: 왼쪽에 배치. 크기 H1 x W2
  • Form3: 왼쪽 하단에 배치. 크기 H1 x W2
  • Form4: 오른쪽에 배치. 크기 H3 x W4

  • Unit1.cpp
    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    
    #include "Unit1.h"
    #include "Unit2.h"
    #include "Unit3.h"
    #include "Unit4.h"
    #include <algorithm> // for std::max()
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        static const int kNumForms = 4;
    
        // Form
        int xpos[kNumForms] = {0,0,0,2};
        int xwid[kNumForms] = {2,2,2,4};
        int ypos[kNumForms] = {0,1,2,0};
        int yhei[kNumForms] = {1,1,1,3};
    
        // Form width and height
        int frmWid = 0;
        int frmHei = 0;
    
        // 1. Find total width and height
        for(int idx=0; idx<kNumForms; idx++) {
            int wid = xpos[idx] + xwid[idx];
            int hei = ypos[idx] + yhei[idx];
            frmWid = std::max(frmWid, wid);
            frmHei = std::max(frmHei, hei);
        }
    
        // 2. calculate divisions for (x,y)
        int xdiv = Screen->Monitors[0]->Width / frmWid;
        int ydiv = Screen->Monitors[0]->Height / frmHei;
    
    // for debug
    //  xdiv = 1280 / frmWid;
    //  ydiv = 768 / frmHei;
    
        TForm *frmPtrs[] = {Form1, Form2, Form3, Form4};
    
        for(int idx=0; idx<kNumForms; idx++) {
            frmPtrs[idx]->Left = xpos[idx] * xdiv;
            frmPtrs[idx]->Top  = ypos[idx] * ydiv;
            frmPtrs[idx]->Width = xwid[idx] * xdiv;
            frmPtrs[idx]->Height = yhei[idx] * ydiv;
        }
    
        // 3. show (Form1 is already shown)
        Form2->Show();
        Form3->Show();
        Form4->Show();
    }
    //---------------------------------------------------------------------------
    


  • C++ Builder XE4의 기능을 사용하여 더 간단한 구현 (디자인)이 있는지 알 수 없습니다
  • 태스크 바의 사이즈 정도는 고려하는 것이 좋을지도
  • h tp : 소 m/7오f9/있어 MS/7아70fdc2C4c157bf025b


  • v0.2 > Taskbar 높이 고려



    Unit1.cpp
    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    
    #include "Unit1.h"
    #include "Unit2.h"
    #include "Unit3.h"
    #include "Unit4.h"
    #include <algorithm> // for std::max()
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        static const int kNumForms = 4;
        static const int kHeightTaskBar = 40;
    
        // Form
        int xpos[kNumForms] = {0,0,0,2};
        int xwid[kNumForms] = {2,2,2,4};
        int ypos[kNumForms] = {0,1,2,0};
        int yhei[kNumForms] = {1,1,1,3};
    
        // Form width and height
        int frmWid = 0;
        int frmHei = 0;
    
        // 1. Find total width and height
        for(int idx=0; idx<kNumForms; idx++) {
            int wid = xpos[idx] + xwid[idx];
            int hei = ypos[idx] + yhei[idx];
            frmWid = std::max(frmWid, wid);
            frmHei = std::max(frmHei, hei);
        }
    
        // 2. calculate divisions for (x,y)
        int xdiv = Screen->Monitors[0]->Width / frmWid;
        int ydiv = (Screen->Monitors[0]->Height - kHeightTaskBar) / frmHei;
    
    // for debug
    //  xdiv = 1280 / frmWid;
    //  ydiv = 768 / frmHei;
    
        TForm *frmPtrs[] = {Form1, Form2, Form3, Form4};
    
        for(int idx=0; idx<kNumForms; idx++) {
            frmPtrs[idx]->Left = xpos[idx] * xdiv;
            frmPtrs[idx]->Top  = ypos[idx] * ydiv;
            frmPtrs[idx]->Width = xwid[idx] * xdiv;
            frmPtrs[idx]->Height = yhei[idx] * ydiv;
        }
    
        // 3. show (Form1 is already shown)
        Form2->Show();
        Form3->Show();
        Form4->Show();
    }
    //---------------------------------------------------------------------------
    

    좋은 웹페이지 즐겨찾기