0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++ Builder 10.2 Tokyo > Forms > Bug > 8個の子フォームを親フォームの下に4行 x 2列で配置する > 空白があいてしまう > 10.2 Tokyoの問題ではなさそう

Last updated at Posted at 2017-12-27
動作環境
Rad Studio 10.2 Tokyo Update 2

c++ builder XE4 > Forms > 8個の子フォームを親フォームの下に4行 x 2列で配置する

XE4で実装したコードは10.2 Tokyoではどう動作するか。

code

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>
#include <Vcl.ComCtrls.hpp>
#include <VCLTee.Chart.hpp>
#include <VCLTee.Series.hpp>
#include <VclTee.TeeGDIPlus.hpp>
#include <VCLTee.TeEngine.hpp>
#include <VCLTee.TeeProcs.hpp>

#include "Unit2.h"
//---------------------------------------------------------------------------

// hogehoge

class TForm1 : public TForm
{
__published:	// IDE で管理されるコンポーネント
	TButton *B_createChild;
	TButton *B_matrix;
	void __fastcall B_createChildClick(TObject *Sender);
	void __fastcall B_matrixClick(TObject *Sender);
private:	// ユーザー宣言
	static const int kNumChild = 8;
	TForm2 *m_childForms[kNumChild];
	void __fastcall putChildrenInMatrix();
public:		// ユーザー宣言
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <DateUtils.hpp>

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}

//---------------------------------------------------------------------------
void __fastcall TForm1::B_createChildClick(TObject *Sender)
{
    for(int idx=0; idx < kNumChild; idx++) {
        m_childForms[idx] = new TForm2(this);
        m_childForms[idx]->Show();
    }
}
//---------------------------------------------------------------------------

static void calcLeftTopOfChildren(int parentTop, int parentHeight, int childIdx, int childWidth, int childHeight, int *dstTop, int *dstLeft)
{
    int topSize, leftSize;

    if (childIdx < 4) {
        topSize = childIdx * childHeight;
        leftSize = 0;
    } else {
        topSize = (childIdx - 4) * childHeight;
        leftSize = childWidth;
    }

    int marginTop = parentTop + parentHeight;

    *dstTop = marginTop + topSize;
    *dstLeft = leftSize;
}

void __fastcall TForm1::putChildrenInMatrix()
{
    TForm2 *formPtr;
    int topPos, leftPos;

    for(int chlIdx=0; chlIdx < kNumChild; chlIdx++) {
        formPtr = m_childForms[chlIdx];

        calcLeftTopOfChildren(this->Top, this->Height, chlIdx, formPtr->Width, formPtr->Height, &topPos, &leftPos);
        formPtr->Top = topPos;
        formPtr->Left = leftPos;
    }
}
void __fastcall TForm1::B_matrixClick(TObject *Sender)
{
    putChildrenInMatrix();
}

結果

10.2 Tokyo + Windows 10 pro

おかしなマージンが入るようになっている。
Windows 10によるものか、10.2 Tokyoによるものか。

qiita.png

XE4 + Windows 7 Pro

下記ではおかしなマージンはなかった。

qiita.png

関連

同じように下記の処理もマージンが発生する。

Windows 8.1 Pro上での動作 (10.2 Tokyoでビルド)

(追記 2018/01/09)

10.2 TokyoでビルドしたソフトをWindows 8.1 Proで実行してみた。

下記のように問題は発生しなかった。
Windows 10 Proで動作した時に座標が変わるのだろうか。

qiita.png

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?