Solved

sizeable form

Posted on 2006-07-12
10
325 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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