Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to resize a TPanel at runtime Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
77
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to resize a TPanel at runtime

Answer:

Solve 1:

You should add a SIZEBOX constant to the your panel window style:

1   TMyNewPanel = class(TPanel)
2     { ... }
3     procedure CreateParams(var Params: TCreateParams); override;
4     { ... }
5   
6     procedure TMyNewPanel.CreateParams(var Params: TCreateParams);
7     begin
8       inherited CreateParams(Params);
9       Params.Style := Params.Style or WS_SIZEBOX;
10    end;



Solve 2:

The best way to deal with this is to make a descendent of TPanel that incorporates 
the required behaviour. Copy the following to a file SizeablePanel.pas, and install 
that via Component -> Install component.

11  unit SizeablePanel;
12  
13  interface
14  
15  uses
16    Messages, Windows, SysUtils, Classes, Controls, ExtCtrls;
17  
18  type
19    TSizeablePanel = class(TPanel)
20    private
21      FMoveable: Boolean;
22      procedure wmNCHittest(var msg: TWMNCHittest); message WM_NCHITTEST;
23    published
24      property Moveable: Boolean read FMoveable write FMoveable default false;
25    end;
26  
27  procedure register;
28  
29  implementation
30  
31  procedure register;
32  begin
33    RegisterComponents('PBGoodies', [TSizeablePanel]);
34  end;
35  
36  procedure TSizeablePanel.wmNCHittest(var msg: TWMNCHittest);
37  var
38    bottom, right: Integer;
39    pt: TPoint;
40  begin
41    if moveable then
42      msg.result := HTCAPTION
43    else
44      inherited;
45    pt := parent.ScreenToClient(SmallpointToPoint(msg.Pos));
46    bottom := Top + Height;
47    right := Left + Width;
48    if (pt.x - Left) < 10 then
49      if (pt.y - Top) < 10 then
50        msg.Result := HTTOPLEFT
51      else if (Bottom - pt.y) < 10 then
52        msg.result := HTBOTTOMLEFT
53      else
54        msg.result := HTLEFT
55    else if (right - pt.x) < 10 then
56      if (pt.y - Top) < 10 then
57        msg.Result := HTTOPRIGHT
58      else if (Bottom - pt.y) < 10 then
59        msg.result := HTBOTTOMRIGHT
60      else
61        msg.result := HTRIGHT
62    else if (pt.y - Top) < 10 then
63      msg.Result := HTTOP
64    else if (Bottom - pt.y) < 10 then
65      msg.result := HTBOTTOM;
66  end;
67  
68  end.




			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC