Link to home
Start Free TrialLog in
Avatar of snoopy_Spy
snoopy_Spy

asked on

Form in a Panel

Can i insert a Form in a Panel ?
I mean can i create different forms in the IDE and than in one form i show a treeview on the left an one of the created forms in the right panel !
Avatar of Nuno1
Nuno1

Please be more specific.

I didnt understand your question..
Avatar of snoopy_Spy

ASKER

OK
I have a Main Form which is divided into 2 Panels. In the left Panel i have a TreeView, where i can select a Form. In the right Panel i would show the Form which i have selected in the Treeview !
Hmmm, how do you want to 'insert'? You can place forms on top of eachother and have them moved, but why not use a panel or groupbox?

Is this what you want?
(drop a button and a panel on a form and insert:)

procedure TForm1.Button1Click(Sender: TObject);
var
  newForm : TForm;
begin
newForm := TForm.create(panel1);
newForm.BorderStyle := bsnone;
newForm.color := clBlue;
newForm.left := form1.left+panel1.left+2;
newForm.top := form1.top+panel1.top+21;
newform.width := panel1.Width;
newForm.height := panel1.height;
newForm.show;
end;

Floris.
Hmmm, how do you want to 'insert'? You can place forms on top of eachother and have them moved, but why not use a panel or groupbox?

Is this what you want?
(drop a button and a panel on a form and insert:)

procedure TForm1.Button1Click(Sender: TObject);
var
  newForm : TForm;
begin
newForm := TForm.create(panel1);
newForm.BorderStyle := bsnone;
newForm.color := clBlue;
newForm.left := form1.left+panel1.left+2;
newForm.top := form1.top+panel1.top+21;
newform.width := panel1.Width;
newForm.height := panel1.height;
newForm.show;
end;

Floris.
Hmmm, how do you want to 'insert'? You can place forms on top of eachother and have them moved, but why not use a panel or groupbox?

Is this what you want?
(drop a button and a panel on a form and insert:)

procedure TForm1.Button1Click(Sender: TObject);
var
  newForm : TForm;
begin
newForm := TForm.create(panel1);
newForm.BorderStyle := bsnone;
newForm.color := clBlue;
newForm.left := form1.left+panel1.left+2;
newForm.top := form1.top+panel1.top+21;
newform.width := panel1.Width;
newForm.height := panel1.height;
newForm.show;
end;

Floris.
oops, how did that happen?
This doesn't work !
It only creates a new form with the left, top, width and height but doesn't move or size !
And when i click on the main form the newForm is send to back.
I want to insert a form (or a Panel) (which controls on it) in a Panel of a main Form.
Again: I wouldn't do it with a form... ...why not another panel? Visual the same, programatically 10 times easier.

Somebody else?

F.

You could try using a frame, MDI, or ActiveForms.

Using Floris idea, you could create your form as any other form, set it's formstyle to be StayOnTop and then rather than create a blank form, just showmodal your form over your main form (you could still create it dynamically if you wanted to)

If I understand your original problem, you want to be able to browse through Delphi forms, loading the one you're interested into the second panel. There isn't a way to do this with forms unless you create something executable with them. ActiveForms will do what you want but are tricky, and I'd go for frames

The Neil
Because i want to show it in two ways :

1.) In a Panel an the right side
2.) With a double click - In a own Form
TheNeil !

I have tried this :

    Panel1.BringtoFront;
    temp := TFrame1.Create(Panel1);
    temp.Show;
    temp.BringtoFront;
    temp.Width := 200;
    temp.Height := 100;
    Panel1.InsertControl(temp);

but it doesn't work !
Hi,

Try this:

I use here a button and a panel on the form1 and previously created form2.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Parent := Form1.Panel1;
  Form2.Left := 0;
  Form2.Top := 0;
  Form2.Height := Panel1.Height;
  Form2.Width := Panel1.Width;
  Form2.Show;
end;

Regards, Geo
Snoopy_Spy,

I've just tried this and it works fine. There are problems if you try to run the code several times without freeing temp first. Have you declared temp properly? I've got it as a global TFrame.

What error messages are you getting and do you have a complete code sample that you can either post or mail?

The Neil
TheNeil,
I have foundthe problem, when i use a TPageControl with no pages it works fine. When i add at least one page it doesn't work (Nothing from the Frame is shown !)
Snoopy_Spy,

Err why are you usig a TPageControl? I got it working first time with a normal TPanel. Can you assign the frame to one of the pages rather than the control itself?
Then again, what does it matter - it works.

Should I be the cheekiest person on the face of the planet and ask who (if anyone) gets the points?

The Neil
I don't know if i understand your comment at all :
What i did was, it had a PageControl on the Frame   . When i add the Frame manually it works fine. When i add the frame programmatically it only works if i have no pages.

The frame is inserted on a standard TPanel !
Snoopy_Spy,

Sorry, I thought you were trying to insert the frame INTO the PageControl - oops

The Neil
Avatar of kretzschmar
hi friends,

yes it is possible.
i would prefer to design the form which should be shown in the panel with borderstyle bsnone and all others as normal design, like

var f : TForm2;
begin
  f := TForm2.Create(Panel1);
  f.BorderStyle := bsNone;
  f.align := alclient;
  f.parent := panel1;
  f.show;
end;

for a pagecontrol:

var
  t : TTabsheet;
  f : TForm2;
begin
  t := TTabsheet.Create(PageControl1);
  t.PageControl := PageControl1;
  t.Caption := IntToStr(PageControl1.PageCount);

  f := TForm2.Create(t);
  f.BorderStyle := bsNone;
  f.align := alclient;
  f.parent := t;
  f.show;

end;


meikl

ps: frames are similar to forms
kretzschmar,
Your first routine doesn't work - The form isn't shown.
Your second routine - i don't want to insert a form (Frame) into a PageControl ! The problem is to insert a frame which contain a PageControl !
hi snoopy,

>Your first routine doesn't work - The form isn't shown.
you dont see it, if the form is empty
(no caption, no min-max-close-sys-buttons,looks like as the panel itselfs)
>to insert a frame which contain a PageControl
just drop a pagecontrol on it and use the first routine

if it not working for you, then leave your email and
i send you my just coded working sample (d3 using a form)

meikl ;-)

Kretzschmar,
I have some Controls on the Form. Itried it with and without a PageControl.
My Email : snoopy@rudolfinum.sth.ac.at
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks
Works fine now
I had set the FormStyle to fsMDIChild . . . . (from previous trying)
Hi,

Try this:

I use here a button and a panel on the form1 and previously created form2.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Parent := Form1.Panel1;
  Form2.Left := 0;
  Form2.Top := 0;
  Form2.Height := Panel1.Height;
  Form2.Width := Panel1.Width;
  Form2.Show;
end;

Regards, Geo