c++ builder XE4 > Form > 4개의 Form을 모니터 가득 정렬
19492 단어 TFormcppBuilder#migrated우이
C++ Builder XE4
4개의 TForm이 있는 앱.
그것을 다음과 같은 배열로 만들고 싶다.
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();
}
//---------------------------------------------------------------------------
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();
}
//---------------------------------------------------------------------------
Reference
이 문제에 관하여(c++ builder XE4 > Form > 4개의 Form을 모니터 가득 정렬), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/7of9/items/b858ea2f947629f47810텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)