Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Create form inside a TPanel component


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 8 - Last Post: Jun 1, 2017 9:24 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Alberto Bonardi

Posts: 4
Registered: 5/22/10
Create form inside a TPanel component  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 4:51 AM
Hello,
i try to develope an application with a main form that have a TPanel component.
I would like that the next forms will be opened/placed inside of the Main Tpanel component.
This is my code for create the new form inside of the Main TPanel:

NewForm := TNewForm.CreateParented(MainForm.Panel1.Handle);
NewForm.Align := alClient;
NewForm .Show;

The new form was opened correctly in the Main Panel, but all the controls (such as a TEdit for example) contained in the New Form are NOT focusable !!

Some idea ??

Thanks a lot !!
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Create form inside a TPanel component  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 7:18 AM   in response to: Alberto Bonardi in response to: Alberto Bonardi
Alberto Bonardi wrote:

Hello,
i try to develope an application with a main form that have a TPanel
component. I would like that the next forms will be opened/placed
inside of the Main Tpanel component. This is my code for create the
new form inside of the Main TPanel:

NewForm := TNewForm.CreateParented(MainForm.Panel1.Handle);
NewForm.Align := alClient;
NewForm .Show;

The new form was opened correctly in the Main Panel, but all the
controls (such as a TEdit for example) contained in the New Form are
NOT focusable !!

Some idea ??

Thanks a lot !!

Why are you using CreateParented? You should not use that method as
it's for a different task. A qoute from the help:

Creates and initializes a control as the child of a specified non-VCL
container.
 
Call CreateParented to embed a new control in a non-VCL parent window.
TActiveXControl objects call CreateParented to create an ActiveX
control as a child of the host application's client site window.
 

What you really should do is:

  NewForm:=TNewForm.Create(nil);
  NewForm.Parent:=Panel1;
  NewForm.Align:=alClient;
  NewForm.Show;
Alberto Bonardi

Posts: 4
Registered: 5/22/10
Re: Create form inside a TPanel component  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 7:42 AM   in response to: Lajos Juhasz in response to: Lajos Juhasz
Lajos Juhasz wrote:
Alberto Bonardi wrote:

Hello,
i try to develope an application with a main form that have a TPanel
component. I would like that the next forms will be opened/placed
inside of the Main Tpanel component. This is my code for create the
new form inside of the Main TPanel:

NewForm := TNewForm.CreateParented(MainForm.Panel1.Handle);
NewForm.Align := alClient;
NewForm .Show;

The new form was opened correctly in the Main Panel, but all the
controls (such as a TEdit for example) contained in the New Form are
NOT focusable !!

Some idea ??

Thanks a lot !!

Why are you using CreateParented? You should not use that method as
it's for a different task. A qoute from the help:

Creates and initializes a control as the child of a specified non-VCL
container.
 
Call CreateParented to embed a new control in a non-VCL parent window.
TActiveXControl objects call CreateParented to create an ActiveX
control as a child of the host application's client site window.
 

What you really should do is:

  NewForm:=TNewForm.Create(nil);
  NewForm.Parent:=Panel1;
  NewForm.Align:=alClient;
  NewForm.Show;

I have already used the code as you suggest, but with always the same result ! I think that there is a problem of Owner or Parent , but i don't know how to resolve. However thank you for your answer.
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Create form inside a TPanel component  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 7:57 AM   in response to: Alberto Bonardi in response to: Alberto Bonardi
Alberto Bonardi wrote:

Lajos Juhasz wrote:
Alberto Bonardi wrote:

Hello,
i try to develope an application with a main form that have a
TPanel component. I would like that the next forms will be
opened/placed inside of the Main Tpanel component. This is my
code for create the new form inside of the Main TPanel:

NewForm := TNewForm.CreateParented(MainForm.Panel1.Handle);
NewForm.Align := alClient;
NewForm .Show;

The new form was opened correctly in the Main Panel, but all the
controls (such as a TEdit for example) contained in the New Form
are NOT focusable !!

Some idea ??

Thanks a lot !!

Why are you using CreateParented? You should not use that method as
it's for a different task. A qoute from the help:

Creates and initializes a control as the child of a specified
non-VCL container.
 
Call CreateParented to embed a new control in a non-VCL parent
window.  TActiveXControl objects call CreateParented to create an
ActiveX control as a child of the host application's client site
window.
 

What you really should do is:

  NewForm:=TNewForm.Create(nil);
  NewForm.Parent:=Panel1;
  NewForm.Align:=alClient;
  NewForm.Show;

I have already used the code as you suggest, but with always the same
result ! I think that there is a problem of Owner or Parent , but i
don't know how to resolve. However thank you for your answer.

That's correct you have to set the parent property of the form the be
the panel as I wrote in my snippet (NewForm.Parent:=Panel1;).

I have tried of course it's also working with CreateParented when you
after create set the parent property. In my test project on the NewForm
there was a single edit and when the application started I was able to
interact with that edit.
Alberto Bonardi

Posts: 4
Registered: 5/22/10
Re: Create form inside a TPanel component  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 8:00 AM   in response to: Lajos Juhasz in response to: Lajos Juhasz
Lajos Juhasz wrote:
Alberto Bonardi wrote:

Lajos Juhasz wrote:
Alberto Bonardi wrote:

Hello,
i try to develope an application with a main form that have a
TPanel component. I would like that the next forms will be
opened/placed inside of the Main Tpanel component. This is my
code for create the new form inside of the Main TPanel:

NewForm := TNewForm.CreateParented(MainForm.Panel1.Handle);
NewForm.Align := alClient;
NewForm .Show;

The new form was opened correctly in the Main Panel, but all the
controls (such as a TEdit for example) contained in the New Form
are NOT focusable !!

Some idea ??

Thanks a lot !!

Why are you using CreateParented? You should not use that method as
it's for a different task. A qoute from the help:

Creates and initializes a control as the child of a specified
non-VCL container.
 
Call CreateParented to embed a new control in a non-VCL parent
window.  TActiveXControl objects call CreateParented to create an
ActiveX control as a child of the host application's client site
window.
 

What you really should do is:

  NewForm:=TNewForm.Create(nil);
  NewForm.Parent:=Panel1;
  NewForm.Align:=alClient;
  NewForm.Show;

I have already used the code as you suggest, but with always the same
result ! I think that there is a problem of Owner or Parent , but i
don't know how to resolve. However thank you for your answer.

That's correct you have to set the parent property of the form the be
the panel as I wrote in my snippet (NewForm.Parent:=Panel1;).

I have tried of course it's also working with CreateParented when you
after create set the parent property. In my test project on the NewForm
there was a single edit and when the application started I was able to
interact with that edit.

Ok, I'll do another test as you say. Thank you !
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Create form inside a TPanel component  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 9:10 AM   in response to: Alberto Bonardi in response to: Alberto Bonardi
Alberto Bonardi wrote:

i try to develope an application with a main form that have a TPanel
component. I would like that the next forms will be opened/placed
inside of the Main Tpanel component.

So, you are trying to re-ccreate what MDI already does?

Personally, I would (and do) use TFrame instead of TForm for this
purpose. TFrame is specifically designed to be embedded in other
controls, like TPanel. TForm is meant to be a free-floating window,
and while it can be embedded, more times than not it causes more
problems than it solves.

--
Remy Lebeau (TeamB)
Bernd Maierhofer

Posts: 161
Registered: 9/27/99
Re: Create form inside a TPanel component  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 10:49 PM   in response to: Alberto Bonardi in response to: Alberto Bonardi
Alberto Bonardi wrote:

Hello,
i try to develope an application with a main form that have a TPanel
component. I would like that the next forms will be opened/placed
inside of the Main Tpanel component. This is my code for create the
new form inside of the Main TPanel:

NewForm := TNewForm.CreateParented(MainForm.Panel1.Handle);
NewForm.Align := alClient;
NewForm .Show;

The new form was opened correctly in the Main Panel, but all the
controls (such as a TEdit for example) contained in the New Form are
NOT focusable !!

Some idea ??

Thanks a lot !!

Is this VCL or FMX?

Bernd

--
Alberto Bonardi

Posts: 4
Registered: 5/22/10
Re: Create form inside a TPanel component  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 12:44 AM   in response to: Bernd Maierhofer in response to: Bernd Maierhofer
Bernd Maierhofer wrote:
Alberto Bonardi wrote:

Hello,
i try to develope an application with a main form that have a TPanel
component. I would like that the next forms will be opened/placed
inside of the Main Tpanel component. This is my code for create the
new form inside of the Main TPanel:

NewForm := TNewForm.CreateParented(MainForm.Panel1.Handle);
NewForm.Align := alClient;
NewForm .Show;

The new form was opened correctly in the Main Panel, but all the
controls (such as a TEdit for example) contained in the New Form are
NOT focusable !!

Some idea ??

Thanks a lot !!

Is this VCL or FMX?

Bernd

--

Is the VCL
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Create form inside a TPanel component  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 9:24 AM   in response to: Bernd Maierhofer in response to: Bernd Maierhofer
Bernd Maierhofer wrote:

Is this VCL or FMX?

VCL, as CreateParented() does not exist in FMX.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02