Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Moving Window Without TitlebarComponent available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi 7.x (or higher)
Category:
VCL-General
Skill Level:
Scoring:
Last Update:
11/25/2008
Search Keys:
delphi delphi3000 article borland vcl code-snippet Moving Window Without Titlebar moving a window with your mouse
Times Scored:
1
Visits:
1506
Uploader: Frank de Hell
Company:
Reference: http://www.superliegebeest.nl/delphi.php#9
Component Download: http://www.superliegebeest.nl/d7/mwwt.zip
 
Question/Problem/Abstract:
This application shows you how to build a form without a titlebar, while still being able to move the window with your mouse. No extra components needed, just delphi, so no hassle with third party components!
Answer:



========================================
========================================
Moving Window Without Titlebar
========================================
========================================
Project1.dpr

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

========================================
Unit1.pas

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure Label1DblClick(Sender: TObject);
    procedure FormDblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

var Moving: boolean;
OldX, OldY, OldLeft, OldTop: integer;
{$R *.DFM}

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   if (Button = mbLeft) then begin
            Moving := True;
            OldX := X;
            OldY := Y;
            OldLeft := X;
            OldTop := Y;
   end;

end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
Moving := false
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
   if Moving then begin
         OldX := X;
       OldY := Y;
            SetBounds( Left+OldX-OldLeft,
                       Top+OldY-OldTop,
                       Width,
                       Height);
   end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Moving := false;
end;

procedure TForm1.Label1DblClick(Sender: TObject);
begin
Close;
end;

procedure TForm1.FormDblClick(Sender: TObject);
begin
Close;
end;

end.

========================================
Unit1.dfm

object Form1: TForm1
  Left = 199
  Top = 162
  BorderStyle = bsNone
  Caption = 'Form1'
  ClientHeight = 446
  ClientWidth = 688
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  OnDblClick = FormDblClick
  OnMouseDown = FormMouseDown
  OnMouseMove = FormMouseMove
  OnMouseUp = FormMouseUp
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 242
    Top = 216
    Width = 204
    Height = 13
    Caption = 'Double-Click anywhere to close this'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
    OnDblClick = Label1DblClick
  end
end

========================================
========================================






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
Hans Gulö
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)