Solved

sizeable form

Posted on 2006-07-12
10
321 Views
Last Modified: 2008-02-01
how can I resize my forms when my forms are set to bsNone can anyone help?
0
Comment
Question by:fiveuk
  • 5
  • 4
10 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17093685
Not a problem, just capture the hit test of the form:

Regards,
Russell

type
  TForm2            =  class(TForm)
  private
     // Private declarations
  protected
     procedure      WMLMouseButtonDown(var Message: TWMMouse); message WM_LBUTTONDOWN;
     procedure      WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
  public
     // Public declarations
  end;

var
  Form2:            TForm2;

const
  BorderSize        =  5;

implementation
{$R *.DFM}

// Catch hit testing on the edge of the window
procedure TForm2.WMNCHitTest(var Message: TWMNCHitTest);
var ptSelf:         TPoint;
begin

  // Inherited
  inherited;

  // Convert screen coord to form coords
  ptSelf:=Self.ScreenToClient(Point(Message.xPos, Message.yPos));

  // Check for edges of form
  if (ptSelf.X <= BorderSize) then
     Message.Result:=HTLEFT
  else if ((ptSelf.X + BorderSize) >= Width) then
     Message.Result:=HTRIGHT
  else if (ptSelf.Y <= BorderSize) then
     Message.Result:=HTTOP
  else if ((ptSelf.Y + BorderSize) >= Height) then
     Message.Result:=HTBOTTOM
  else
     // Return client
     Message.Result:=HTCLIENT;

end;

// Allow form dragging
procedure TForm2.WMLMouseButtonDown(var Message: TWMMouse);
begin

  ReleaseCapture;
  SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);

end;

0
 
LVL 6

Expert Comment

by:House_of_Dexter
ID: 17093691
drop a 2 TUpDown component on your form... set the Min Max to the size req. of your form


//do the same code for the width...setting AlignButtons to buttons to udleft for the width
procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
begin
  Form1.Height := UpDown1.Position;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  UpDown1.Position := Form1.Height
end;
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17093724

Allows for diagonal arrows when at topleft, topright, bottomleft, bottomright.

procedure TForm2.WMNCHitTest(var Message: TWMNCHitTest);
var ptSelf:         TPoint;
begin

  // Inherited
  inherited;

  // Convert screen coord to form coords
  ptSelf:=Self.ScreenToClient(Point(Message.xPos, Message.yPos));

  // Check for edges of form
  if (ptSelf.X <= BorderSize) then
  begin
     if (ptSelf.Y <= BorderSize) then
        Message.Result:=HTTOPLEFT
     else if ((ptSelf.Y + BorderSize) >= Height) then
        Message.Result:=HTBOTTOMLEFT
     else
        Message.Result:=HTLEFT ;
  end
  else if ((ptSelf.X + BorderSize) >= Width) then
  begin
     if (ptSelf.Y <= BorderSize) then
        Message.Result:=HTTOPRIGHT
     else if ((ptSelf.Y + BorderSize) >= Height) then
        Message.Result:=HTBOTTOMRIGHT
     else
        Message.Result:=HTRIGHT;
  end
  else if (ptSelf.Y <= BorderSize) then
     Message.Result:=HTTOP
  else if ((ptSelf.Y + BorderSize) >= Height) then
     Message.Result:=HTBOTTOM
  else
     // Return client
     Message.Result:=HTCLIENT;

end;

Of course if you need to do it via code, then setting Width/Height or using SetBounds always works

Russell

0
 

Author Comment

by:fiveuk
ID: 17093918
I just want to be able to drag the window to resize it like it would when it has sizewindow enabled how can I do that???
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17093963

I *ALREADY* gave you the code to do it. What part aren't you understanding???

Russell
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:fiveuk
ID: 17093978
what is WMNCHitTest ????
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17094046
Its a procedure that needs to be added to your form, along with WMLMouseButtonDown to handle the required window messages. More specifically, they are message handlers. You should have added the code I gave you to your form declarations.

Alternatively, you can wrap up the code I gave you into a class, and then use this class for your form. For example, if you have a form called Form1, then the code would be:

unit Unit1;

interface

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

const
  BorderSize        =  5;

type
  TSizeForm         =  class(TForm)
  protected
     procedure      WMLMouseButtonDown(var Message: TWMMouse); message WM_LBUTTONDOWN;
     procedure      WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
  end;

type
  TForm1            =  class(TSizeForm) // TForm now inherits from TSizeForm instead of TForm
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

// Code for TSizeForm
procedure TSizeForm.WMNCHitTest(var Message: TWMNCHitTest);
var ptSelf:         TPoint;
begin

  // Inherited
  inherited;

  // Convert screen coord to form coords
  ptSelf:=Self.ScreenToClient(Point(Message.xPos, Message.yPos));

  // Check for edges of form
  if (ptSelf.X <= BorderSize) then
  begin
     if (ptSelf.Y <= BorderSize) then
        Message.Result:=HTTOPLEFT
     else if ((ptSelf.Y + BorderSize) >= Height) then
        Message.Result:=HTBOTTOMLEFT
     else
        Message.Result:=HTLEFT ;
  end
  else if ((ptSelf.X + BorderSize) >= Width) then
  begin
     if (ptSelf.Y <= BorderSize) then
        Message.Result:=HTTOPRIGHT
     else if ((ptSelf.Y + BorderSize) >= Height) then
        Message.Result:=HTBOTTOMRIGHT
     else
        Message.Result:=HTRIGHT;
  end
  else if (ptSelf.Y <= BorderSize) then
     Message.Result:=HTTOP
  else if ((ptSelf.Y + BorderSize) >= Height) then
     Message.Result:=HTBOTTOM
  else
     // Return client
     Message.Result:=HTCLIENT;

end;

procedure TSizeForm.WMLMouseButtonDown(var Message: TWMMouse);
begin

  ReleaseCapture;
  SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);

end;

end.
0
 

Author Comment

by:fiveuk
ID: 17094047
I tryed the code but it dont work am using panels for to make my interface with out caption bar
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 50 total points
ID: 17094254
Well if you cover the whole form and there is no window edge, then you are not going to get a hit test, are you? It helps to mention details such as this. The code below adds a static edge which will allow you to process the hit test, but as for dragging the form around, you are going to have to implement the OnMouseDown event for those controls that you wish to act like the caption bar, then insert the following code:

  ReleaseCapture;
  SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);


-------

unit Unit1;

interface

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

const
  BorderSize        =  5;

type
  TSizeForm         =  class(TForm)
  protected
     procedure      WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
     procedure      CreateParams(var Params: TCreateParams); override;
  end;

type
  TForm1            =  class(TSizeForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

// Code for TSizeForm
procedure TSizeForm.CreateParams(var Params: TCreateParams);
begin

  // Inherited
  inherited;

  // Set extended style
  Params.ExStyle:=Params.ExStyle or WS_EX_STATICEDGE;

end;

procedure TSizeForm.WMNCHitTest(var Message: TWMNCHitTest);
var ptSelf:         TPoint;
begin

  // Inherited
  inherited;

  // Convert screen coord to form coords
  ptSelf:=Self.ScreenToClient(Point(Message.xPos, Message.yPos));

  // Check for edges of form
  if (ptSelf.X <= BorderSize) then
  begin
     if (ptSelf.Y <= BorderSize) then
        Message.Result:=HTTOPLEFT
     else if ((ptSelf.Y + BorderSize) >= Height) then
        Message.Result:=HTBOTTOMLEFT
     else
        Message.Result:=HTLEFT ;
  end
  else if ((ptSelf.X + BorderSize) >= Width) then
  begin
     if (ptSelf.Y <= BorderSize) then
        Message.Result:=HTTOPRIGHT
     else if ((ptSelf.Y + BorderSize) >= Height) then
        Message.Result:=HTBOTTOMRIGHT
     else
        Message.Result:=HTRIGHT;
  end
  else if (ptSelf.Y <= BorderSize) then
     Message.Result:=HTTOP
  else if ((ptSelf.Y + BorderSize) >= Height) then
     Message.Result:=HTBOTTOM
  else
     // Return client
     Message.Result:=HTCLIENT;

end;

end.
0
 

Author Comment

by:fiveuk
ID: 17094431
that worked spot on cheer mate :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 205
Delphi component that can load a DLL in design time? 8 53
Simple Delphi Question 9 83
Intraweb download file link ? 1 109
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now