João Rocha
João Rocha

Reputation: 135

Is it possible to drag a TPanel to outside the TForm?

I'm wondering if it's possible to make something like this:

image

but without creating a second TForm.

I'm using Delphi 7, but if a newer version make it possible just tell me.

Upvotes: 0

Views: 700

Answers (1)

MartynA
MartynA

Reputation: 30715

I've always thought the DockEx demo was over-complicated for learning the basics of docking.

The following is the simplest example I know of:

  • Add a TPanel to a blank form and set its DragKind property to dkDock, DragMode to dmAutomatic and its Align property to alTop.

  • Drop a TButton on the TPanel

  • Add the code below to the form:

  • Run the project and manually drag the panel off the form.

  • Click Button1.

The above shows how Delphi can undock a Panel (or TEdit, etc) without you needing to create a second form to host it while undocked, like Remy said in a comment. The Button1 click-handler shows a way (admittedly imperfect) of re-docking the panel. Next:

  • Undock the panel again, but this time, click the Close button on its auto-created host.

Then, read the OLH and figure out a) how to get the now-hidden panel visible again and b) to re-position & re-align it on the form as it was prior to undocking,

  type
    TMyClass = TControl;

  procedure TForm1.Button1Click(Sender: TObject);
  begin
    TMyClass(Panel1).ManualDock(Self, Nil, alNone);
  end;

Upvotes: 3

Related Questions