Solved

dragging and dropping forms

Posted on 2002-06-18
7
355 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Performance of SQL statement 37 137
TEMBEDDEDWB how can i change its user agent ? 8 83
How to convert memory stream to PDF file 6 177
Delphi Firemonkey send email on Android 1 42
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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