Board index » delphi » Size Grip Handle on a TForm

Size Grip Handle on a TForm


2004-01-24 07:54:34 AM
delphi144
Is there a way to easily add the sizing grip handle to a TForm without using
TStatusbar component?
Thanks,
 
 

Re:Size Grip Handle on a TForm

You can display a small grip icon by calling :
DrawFrameControl(Canvas.Handle,Rect(x,y,w,h),DFC_SCROLL,DFCS_SCROLLSIZEGRIP)
;
where x, y are the coordinates of the top left corner of the glyph
(Self.clientwith-"glyph".width,Self.clientheight-"glyph".height).
w and h are the width and the height of the control. I think the size is
typicaly a square of 16 pixels of dimension.
To make this glyph active, you may catch the WM_NCHITTEST of the window and
return HTSIZE if the mouse cursor is in this square.
Florent
"Reid Roman" <XXXX@XXXXX.COM>a écrit dans le message de
Quote
Is there a way to easily add the sizing grip handle to a TForm without
using
TStatusbar component?

Thanks,
--
Reid Roman
Future Generation Software
www.fgsoft.com


 

Re:Size Grip Handle on a TForm

Hello Florent,
Thanks for the response.
I am not an API guru so please forgive me.
I did a search on this method and found this:
216.101.185.148/scripts/isapi.dll/article
It mentions that the XP look and feel will be overridden by the use of this
method. Have you been successful using this method while maintaining the XP
style?
 

Re:Size Grip Handle on a TForm

Reid Roman writes:
Quote
Hello Florent,

Thanks for the response.

I am not an API guru so please forgive me.

I did a search on this method and found this:

216.101.185.148/scripts/isapi.dll/article

It mentions that the XP look and feel will be overridden by the use
of this method. Have you been successful using this method while
maintaining the XP style?
Hi Roman,
We are using a similar method with XP, it works well.
We took an image for the grip and adjust it manually on resizing of the
form. (Anchors do not work correctly with toolwindows or if the window
caption is not the same as in design time).
TxxDlg = class(TForm)
SizeGripImage: TImage;
...
procedure TxxDlg.SizeGripImageMouseDown(Sender: TObject; Button:
TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
// release mouse button
postmessage(Handle, WM_LBUTTONUP, MK_LBUTTON, 0);
application.ProcessMessages;
// simulate size click
postmessage(Handle, WM_NCLBUTTONDOWN, HTBOTTOMRIGHT, 0)
end;
procedure TxxDlg.FormResize(Sender: TObject);
begin
// adjust size grip position
SizeGripImage.SetBounds(clientrect.Right - SizeGripImage.Width,
clientrect.Bottom - SizeGripImage.Height, SizeGripImage.Width,
SizeGripImage.Height);
end;
Achim
 

Re:Size Grip Handle on a TForm

Hello Achim,
I tried your approach and find that the image is offset up to the left and
top of the form by an inch or so. I can resize the form by dragging it as
needed though.
The problem I am having is that on my project's form I need to have a TPanel
set to alClient as the backdrop panel for the form. On that panel I have
other panels and controls.
When I create a demo with the code below it works as I mentioned above but
when I add the TPanel to the TForm and set it is Align property to alClient I
cannot see or use the GripHandle.
And suggestions?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
FSizeGripImage: TImage;
procedure FSizeGripImageMouseDown(Sender: TObject; Button:
TMouseButton;
Shift: TShiftState; X, Y: Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
FSizeGripImage := TImage.Create(Self);
FSizeGripImage.Picture.LoadFromFile('SizeGripHandle.bmp');
FSizeGripImage.Parent := Self;
FSizeGripImage.Visible := TRUE;
FSizeGripImage.OnMouseDown := FSizeGripImageMouseDown;
FSizeGripImage.Cursor := crSizeNWSE;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeAndNil(FSizeGripImage);
end;
procedure TForm1.FSizeGripImageMouseDown(Sender: TObject; Button:
TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
// release mouse button
postmessage(Handle, WM_LBUTTONUP, MK_LBUTTON, 0);
application.ProcessMessages;
// simulate size click
postmessage(Handle, WM_NCLBUTTONDOWN, HTBOTTOMRIGHT, 0)
end;
procedure TForm1.FormResize(Sender: TObject);
begin
// adjust size grip position
FSizeGripImage.SetBounds(clientrect.Right - FSizeGripImage.Width,
clientrect.Bottom - FSizeGripImage.Height, FSizeGripImage.Width,
FSizeGripImage.Height);
end;
end.
 

Re:Size Grip Handle on a TForm

Florent,
Using your hint I am able to add the size grip to the form natively without
using a bitmap approach that Achim suggested but the problem still exists
with the main TPanel set to alClient. (also I do not have XP so I cannot
test to see if it works in that environment without using the bitmap
approach).
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
FSizeGripRect : TRect;
FSizeGripWidth : Integer;
FSizeGripHeight : Integer;
protected
procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST ;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
inherited;
if PtInRect(FSizeGripRect, ScreenToClient(SmallPointToPoint(Msg.Pos)))
then
Msg.Result := HTBOTTOMRIGHT;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FSizeGripWidth := GetSystemMetrics(SM_CXVSCROLL);
FSizeGripHeight := GetSystemMetrics(SM_CYHSCROLL);
end;
procedure TForm1.FormResize(Sender: TObject);
begin
FSizeGripRect := ClientRect;
FSizeGripRect.Left := FSizeGripRect.Right - FSizeGripWidth;
FSizeGripRect.Top := FSizeGripRect.Bottom - FSizeGripHeight;
Refresh;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
DrawFrameControl(Canvas.Handle, FSizeGripRect,
DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
end;
end.
 

Re:Size Grip Handle on a TForm

Reid Roman writes:
Quote
Hello Achim,

I tried your approach and find that the image is offset up to the
left and top of the form by an inch or so. I can resize the form by
dragging it as needed though.

The problem I am having is that on my project's form I need to have a
TPanel set to alClient as the backdrop panel for the form. On that
panel I have other panels and controls.

When I create a demo with the code below it works as I mentioned
above but when I add the TPanel to the TForm and set it is Align
property to alClient I cannot see or use the GripHandle.

And suggestions?


You can place the image, its picture and its cursor on the form at design
time.
If your Panel hides the image, bring the image to front (rightclick image in
designer->Element...)
good luck
Achim
 

Re:Size Grip Handle on a TForm

Achim,
If I am not mistaken, a TImage has to have a Parent. And when you set the
parent to the form is will be behind the TPanel.
 

Re:Size Grip Handle on a TForm

I try this program, it work fine with a TPaintBox (Anchors =
[akRight,akBottom]) placed on the TPanel (Align=alClient) :
the .pas file
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
PaintBox1: TPaintBox;
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
protected
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
PaintBox1.Width:= GetSystemMetrics(SM_CXVSCROLL);
PaintBox1.Height:= GetSystemMetrics(SM_CYHSCROLL);
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
with (Sender as TPaintBox) do
DrawFrameControl(Canvas.Handle, ClientRect,DFC_SCROLL,
DFCS_SCROLLSIZEGRIP);
end;
procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
PaintBox1.Perform(WM_LBUTTONUP, MK_LBUTTON, X or (Y shl 16));
PostMessage(Handle, WM_NCLBUTTONDOWN, HTBOTTOMRIGHT, X or (Y shl 16));
end;
end.
the .dfm file
object Form1: TForm1
Left = 198
Top = 103
Width = 604
Height = 397
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 596
Height = 370
Align = alClient
BevelOuter = bvNone
Caption = 'Panel1'
TabOrder = 0
DesignSize = (
596
370)
object PaintBox1: TPaintBox
Left = 580
Top = 354
Width = 16
Height = 16
Cursor = crSizeNWSE
Anchors = [akRight, akBottom]
OnMouseDown = PaintBox1MouseDown
OnPaint = FormPaint
end
end
end
I tested it with Delphi 6 Update 2 on Windows 2000 pro SP4.
Regards,
Florent
"Reid Roman" <XXXX@XXXXX.COM>a écrit dans le message de
Quote
Florent,

Using your hint I am able to add the size grip to the form natively
without
using a bitmap approach that Achim suggested but the problem still exists
with the main TPanel set to alClient. (also I do not have XP so I cannot
test to see if it works in that environment without using the bitmap
approach).

unit Unit1;

interface

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

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
FSizeGripRect : TRect;
FSizeGripWidth : Integer;
FSizeGripHeight : Integer;


protected
procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST ;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
inherited;
if PtInRect(FSizeGripRect, ScreenToClient(SmallPointToPoint(Msg.Pos)))
then
Msg.Result := HTBOTTOMRIGHT;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FSizeGripWidth := GetSystemMetrics(SM_CXVSCROLL);
FSizeGripHeight := GetSystemMetrics(SM_CYHSCROLL);
end;

procedure TForm1.FormResize(Sender: TObject);
begin
FSizeGripRect := ClientRect;
FSizeGripRect.Left := FSizeGripRect.Right - FSizeGripWidth;
FSizeGripRect.Top := FSizeGripRect.Bottom - FSizeGripHeight;
Refresh;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
DrawFrameControl(Canvas.Handle, FSizeGripRect,
DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
end;

end.



--
Reid Roman
Future Generation Software
www.fgsoft.com