Solved

dragging and dropping forms

Posted on 2002-06-18
7
367 Views
Last Modified: 2010-04-04
Hi there,

I have a few standard little forms in my application. I show these forms on top of my application, they are pretty small because all they contain are some textboxes. On the main form, I want to be able to drag these standard forms to the leftside of the main form and 'snap' them to that side. Just like toolbars you can drag/drop. Any idea how to accomplish this?

Bye,
Jeroen
0
Comment
Question by:jccommandeur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 6

Accepted Solution

by:
edey earned 100 total points
ID: 7090031
you can call manulaDock to get the little forms docked, the tricky part is knowing when. TCustomForm doesn't have a OnMoving event, but the form will get WM_MOVE and WM_WINDOWPOSCHANGING messages. All you have to do is catch either one, test whether the form is closed enough to the edge of the first yet, and if it is then call manualDock.

GL
Mike

an example for the form to be docked:

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
  private
         procedure doMove(var msg : TWMMOVE);message WM_MOVE;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.doMove(var msg : TWMMOVE);
begin
     if abs(msg.XPos - form1.left) < 20 then
     begin
          if abs(form1.Top+(form1.Height div 2)-msg.YPos) <= form1.Height div 2 then
             manualDock(form1,nil,alLeft);
     end;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
     show;
end;

end.
0
 

Author Comment

by:jccommandeur
ID: 7090829
Thanks edey, this is starting to look like it. But... after docking the form, I also want to be able to undock and move it around like usual. You know, just like ordinary toolbars etc. Is that possible?

Jeroen
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7091584
Something like this?

Form1:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ToolWin, ComCtrls;

type
  TForm1 = class(TForm)
    ToolBar1: TToolBar;
    procedure ToolBar1UnDock(Sender: TObject; Client: TControl;
      NewTarget: TWinControl; var Allow: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ToolBar1UnDock(Sender: TObject; Client: TControl;
  NewTarget: TWinControl; var Allow: Boolean);
begin
  Allow := True;
end;

end.



And the form content:

object Form1: TForm1
  Left = 220
  Top = 138
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ToolBar1: TToolBar
    Left = 0
    Top = 0
    Width = 688
    Height = 29
    AutoSize = True
    Caption = 'ToolBar1'
    DockSite = True
    DragKind = dkDock
    TabOrder = 0
    OnUnDock = ToolBar1UnDock
  end
end
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7091586
Form2's code:

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type
  TForm2 = class(TForm)
    Panel1: TPanel;
    procedure FormCreate(Sender: TObject);
    procedure FormDblClick(Sender: TObject);
    procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormStartDock(Sender: TObject;
      var DragObject: TDragDockObject);
  private
    { Private declarations }
  public
    { Public declarations }
    isMouseDown: Boolean;
    OldWidth, OldHeight: Integer;
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.FormCreate(Sender: TObject);
begin
  isMouseDown := False;
end;

procedure TForm2.FormDblClick(Sender: TObject);
begin
  ShowMessage('Hi!');
end;

procedure TForm2.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  isMouseDown := True;
end;

procedure TForm2.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  isMouseDown := False;
end;

procedure TForm2.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  APoint: TPoint;
begin
  if isMouseDown then
    if not Floating then
    begin
      isMouseDown := False;
      APoint := ClientToScreen(Point(X, Y));
      ManualFloat(Rect(APoint.x, APoint.y,
        OldWidth + APoint.x, APoint.y + OldHeight));
    end;
end;

procedure TForm2.FormStartDock(Sender: TObject;
  var DragObject: TDragDockObject);
begin
  OldWidth := Width;
  OldHeight := Height;
end;

end.



And the content:

object Form2: TForm2
  Left = 657
  Top = 101
  Width = 284
  Height = 227
  Caption = 'Form2'
  Color = clYellow
  DragKind = dkDock
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  Visible = True
  OnCreate = FormCreate
  OnDblClick = FormDblClick
  OnStartDock = FormStartDock
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 276
    Height = 200
    Align = alClient
    BevelOuter = bvNone
    Caption = 'Panel1'
    Color = clYellow
    TabOrder = 0
    OnMouseDown = Panel1MouseDown
    OnMouseMove = Panel1MouseMove
    OnMouseUp = Panel1MouseUp
  end
end










HTH
DragonSlayer
0
 

Author Comment

by:jccommandeur
ID: 7091996
DragonSlayer,

I don't get what you're trying to do here. Can you explain?

Jeroen
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7092072
umm... create two forms, form1 and form2.

at form1, right-click and choose view as text, then replace the content with the form1 content (above). also, replace the form's code with the form1 code above. Repeat for form2. Then run the programme.
0
 

Author Comment

by:jccommandeur
ID: 7092142
I understand that part, but I don't see what the program is supposed to do. Are you trying to dock form2 in the toolbar of form1? If so, it doesn't work here... maybe you can send me a working example to jeroen.commandeur@hccnet.nl? thanks in advance!

Jeroen
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question