LoginSignup
0
0

More than 5 years have passed since last update.

C++ Builder XE4 > UI > 画面N分割したサイズにソフトウェアを変更するUI例

Last updated at Posted at 2018-12-10
動作環境
C++ Builder XE4

処理概要

  • ソフトウェアのサイズをモニタ画面サイズのN分割とする
  • 縦に1..3分割、横に1..3分割
  • どのようなUIにすると分かりやすいか

実装

Unit1.h
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE で管理されるコンポーネント
    TComboBox *CB_vertDiv;
    TComboBox *CB_horiDiv;
    TShape *SHP_screen;
    TShape *SHP_software;
    TLabel *L_softcaption;
    void __fastcall FormShow(TObject *Sender);
    void __fastcall CB_vertDivChange(TObject *Sender);
    void __fastcall CB_horiDivChange(TObject *Sender);
private:    // ユーザー宣言
    int original_width;
    int original_height;
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)
{
    this->Caption = L"Display size";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
    original_width = this->Width;
    original_height = this->Height;

    // 左上合わせ (デザインで重なりが分かるようにずらしているためコードで合わせる)
    SHP_software->Left = SHP_screen->Left;
    SHP_software->Top  = SHP_screen->Top;
    L_softcaption->Left = SHP_screen->Left;
    L_softcaption->Top = SHP_screen->Top;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::CB_vertDivChange(TObject *Sender)
{
    int val = StrToIntDef(CB_vertDiv->Text, 0);
    if (val == 0) {
        return;
    }

    SHP_software->Height = SHP_screen->Height / val;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CB_horiDivChange(TObject *Sender)
{
    int val = StrToIntDef(CB_horiDiv->Text, 0);
    if (val == 0) {
        return;
    }

    SHP_software->Width = SHP_screen->Width / val;
}
//---------------------------------------------------------------------------

フォームデザイン

2018-12-10_18h02_33.png

動作例

2018-12-10_18h01_17.png

2018-12-10_18h01_24.png

2018-12-10_18h01_29.png

工夫

左上にソフトウェアキャプション「XXX Software」とつけた。
これがないと二分割した時に「どちらがソフトウェアだろう?」という疑問が発生する。

関連

画面設定例

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0