0
0

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 3 years have passed since last update.

C++ Builder 10.2 Tokyo > Form in Formの試用 > TEditに入力ができなくなる > TFrameを使う

Last updated at Posted at 2020-07-12
動作環境
Windows 10 Pro v1909
RAD Studio 10.2 Tokyo Update 3

Form in Form

TFormの中にTFormを入れる方法が下記に紹介されている。

Delphi実装をC++ Builder実装にしてみた。

Unit1 > 親フォーム

親となるフォームは下記のデザインとソースとしている。

Form1.png

Unit1.hpp
//---------------------------------------------------------------------------

# 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 "Unit2.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE で管理されるコンポーネント
	TPanel *Panel1;
	void __fastcall FormCreate(TObject *Sender);
private:	// ユーザー宣言
	TForm2 *m_form2;
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)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
	m_form2 = new TForm2(this);
	m_form2->Parent = Panel1;
	m_form2->Align = alClient;
	m_form2->Visible = true;
}
//---------------------------------------------------------------------------

子フォーム

子フォームは下記のデザインとしている。
ソースはデフォルトから変更せず。

Form2.png

実行結果

実行すると下記のようになる。

RunExample.png

問題点

Form in Formで実行したところ、「TEditマウスクリック選択時に入力ができない」問題が発生するようだ。
一方で、タブキー移動でTEditにフォーカスを移した時はTEditに入力はできる。

代わり

上記のStackOverflowのリンクにもあるように、TForm in TFormにせずにTFrame in TFormにする方が良さそう。
TFrameをTPanelに割り当てした場合は、TEditの入力不可問題は発生しない。

0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?