Solved

sizeable form

Posted on 2006-07-12
10
318 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
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, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 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

19 Experts available now in Live!

Get 1:1 Help Now