[Obsolete] C++ Builder XE4 > geometry > 右配置のTEditのフォントサイズを拡大時、左配置のTChartを残りスペースで描画するサイズに落とす > Font->Size変更後に他の値を自動計算
動作環境
C++ Builder XE4
Obsolete
(追記 2018/10/22)
下記の記載内容よりより良い実装が見つかったので、この記事は「Obsolete(廃版、非推奨、旧版)」扱いとします。
推奨は以下。
v0.1 > 横方向の調整
処理概要
- TChartが左に、TEditが右に配置されている
- TEditのフォントサイズを拡大できるように
- SVGAから4K UHD表示対応
- フォントサイズ変更時、TEditのWidthを自動変更
- 文字数があまり変わらないように
- TEditのRightは固定
- TChartのWidthは残りスペースで描画できるようにする
- 変更はフォントサイズのみとして、残りの値は自動計算する
フォームデザイン
以下のようにアンカーを設定している。
- Edit1, Label1, B_large
- Anchors: akTop, akRight
- Chart1
- Anchors: akLeft, akTop, akRight, akBottom
実装
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)
{
Edit1->Text = L"12345678901234567890";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::B_largeClick(TObject *Sender)
{
// 右配置のTEditのサイズを変更時、左配置のTChartのサイズを調整する
// (TChartを残りスペースで描画する)
int org = Edit1->Height;
Edit1->Font->Size += 2;
int displacement = Edit1->Height - org;
displacement += 12; // 12: 任意の値 (結果を見ながらTEditの文字数があまり変わらないよう調整した)
displacement *= 2; // 2: 左右
Edit1->Width += displacement;
Edit1->Left -= displacement;
Chart1->Width -= displacement;
}
//---------------------------------------------------------------------------
結果!
v0.2 > 縦横方向の調整
縦方向の調整も加えた。
実装
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)
{
Edit1->Text = L"12345678901234567890";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::B_largeClick(TObject *Sender)
{
// 右配置のTEditのサイズを変更時、左配置のTChartのサイズを調整する
// (TChartを残りスペースで描画する)
int org = Edit1->Height;
Edit1->Font->Size += 2;
int displacement = Edit1->Height - org;
displacement += 12; // 12: 任意の値 (結果を見ながらTEditの文字数があまり変わらないよう調整した)
displacement *= 2; // 2: 左右
Edit1->Width += displacement;
Edit1->Left -= displacement;
// 横方向の調整
Chart1->Width -= displacement;
// 縦方向の調整
int vertical = Edit1->Height - org;
Chart1->Top += vertical;
Chart1->Height -= vertical;
}
//---------------------------------------------------------------------------
結果
Author And Source
この問題について([Obsolete] C++ Builder XE4 > geometry > 右配置のTEditのフォントサイズを拡大時、左配置のTChartを残りスペースで描画するサイズに落とす > Font->Size変更後に他の値を自動計算), 我々は、より多くの情報をここで見つけました https://qiita.com/7of9/items/f7d50421ac6bbaaffc5c著者帰属:元の著者の情報は、元の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 .