Thema: Delphi Easymove

Einzelnen Beitrag anzeigen

Benutzerbild von APP
APP

Registriert seit: 24. Feb 2003
Ort: Graz (A)
705 Beiträge
 
Delphi 7 Enterprise
 
#6
  Alt 15. Apr 2003, 17:09
Hallo,

ich glaube Du mußt es umgekehrt machen:

Zitat:
But, I have components on a form!?
In most cases we'll have some components on a form. Let's say, for example, that one Panel object is on a form. If Align property of a panel is set to alClient, the Panel fills the entire client area so that it is impossible to select the parent form by clicking on it. The code above will not work! Why? The code above will not work because the mouse is always moving over the Panel component not the form.

To move our form by dragging a panel on the form we have to add few lines of code in the OnMouseDown event procedure for the Panel component:

procedure TForm1.Panel1MouseDown
(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(Form1.Handle, WM_SYSCOMMAND, 61458, 0);
end;

Note: this code will not work with non-window controls such as TLabel components
Du legst ein Panel auf Deine Form mit Align at Client, dann platzierst Du deine Controls (Buttons,...) die Du bedienen möchtest darauf.

Dann kommt:
Delphi-Quellcode:
unit bUnit1;

interface

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

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    procedure Button1Click(Sender: TObject);
    procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
  procedure WMNCHitTest(var Msg: TWMNCHitTest);
  message wm_NCHitTest;


    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
  inherited;
  if Msg.Result = htClient then
    Msg.Result := htCaption;
end;

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  SendMessage(Form1.Handle, WM_SYSCOMMAND, 61458, 0);
end;
und nun kannst Du die Form (über das Panel) verschieben und trotzdem die Buttons drücken.

(Frei nach Another Way to Drag a Window auf About.com)

[EDIT] Habe gerade bemerkt, dass es auch ohne Panel funkt, so wie es City Light beschrieben hat!! [/EDIT]
Armin P. Pressler

BEGIN
...real programmers are using C/C++ - smart developers Delphi;
END;
  Mit Zitat antworten Zitat