[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

sizeable form

Posted on 2006-07-12
10
Medium Priority
?
339 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

650 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