Solved

sizeable form

Posted on 2006-07-12
10
329 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
[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
  • 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
Technology Partners: 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!

 

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
 

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how can i search if string exist in array ? 3 76
Delphi and Access based Enumeration 9 87
Firemonkey BASS_Init into a thread 17 79
Firemonkey Tcameracomponent resultion 1 44
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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