Article View: borland.public.cppbuilder.nativeapi
Article #14524Re: How to resize a control when run-time
From: Rodolfo Frino
Date: Sun, 10 Aug 2003 03:08
Date: Sun, 10 Aug 2003 03:08
133 lines
5617 bytes
5617 bytes
The easiest way of resizing a control at run time is to use
the undocumented Windows constants wParam (see SendMessage win32 API
or Perform VCL function that encapsulates SendMessage) that I discovered
while experimenting with these functions:
The mouse functionality is as follows:
Right Button of the Mouse triggers the actions given in the table below.
Right Button of the mouse stops the actions.
The differences are subtle, for example the behaviour for
0xF007 and 0xF008 differs in the minimum size of the control
along the axes.
Example:
WParam (Perform)
wParam (SendMessage) Behaviour
-----------------------------------------------------------
0xF009 Adjusts control Position
-----------------------------------------------------------
0xF008 Adjusts both control Width and Height
-----------------------------------------------------------
0xF007 Adjusts both control Width and Height
-----------------------------------------------------------
0xF006 Adjusts control Height
-----------------------------------------------------------
0xF003 Adjusts control Height
-----------------------------------------------------------
0xF002 Adjusts control Width
-----------------------------------------------------------
0xF001 Adjusts control Width
-----------------------------------------------------------
TBitBtn* BitBtn1;
TButton* Button1;
TPanel* Panel1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Width = 600;
Height = 300;
Color = (TColor)0x653dca;
Position = poScreenCenter;
Button1 = new TButton(this);
Button1->Parent = this;
Button1->Top = 50;
Button1->Width = 150;
Button1->Left = Width/2 - Button1->Width/2;
Button1->Height = 100;
Button1->Caption = "Button1";
Button1->OnMouseDown = Button1MouseDown;
Button1->OnClick = Button1Click;
BitBtn1 = new TBitBtn(this);
BitBtn1->Parent = this;
BitBtn1->Top = Button1->Top;
BitBtn1->Left = Button1->Left - Button1->Width - 50;
BitBtn1->Width = Button1->Width;
BitBtn1->Height = Button1->Height;
BitBtn1->Caption = "BitBtn1";
BitBtn1->OnMouseDown = BitBtn1MouseDown;
BitBtn1->OnClick = BitBtn1Click;
Panel1 = new TPanel(this);
Panel1->Parent = this;
Panel1->Top = Button1->Top;
Panel1->Left = Button1->Left + Button1->Width + 50;
Panel1->Width = Button1->Width;
Panel1->Height = Button1->Height;
Panel1->Caption = "Panel1";
Panel1->OnMouseDown = Panel1MouseDown;
Panel1->OnClick = Panel1Click;
}
//----------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
//ShowMessage("BitBtn1 Click");
}
//----------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//ShowMessage("Button1 Click");
}
//----------------------------------------------------------------------
void __fastcall TForm1::Panel1Click(TObject *Sender)
{
//ShowMessage("Panel1 Click");
}
//----------------------------------------------------------------------
void __fastcall TForm1::BitBtn1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
// Adjust control Width by setting either WParam = 0xF001 or WParam = 0xF002
if (Button == mbRight)
BitBtn1->Perform(WM_SYSCOMMAND, 0xF001, 0);
}
//----------------------------------------------------------------------
void __fastcall TForm1::Button1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
// Adjust control Height by setting WParam = 0xF003 or WParam = 0xF006
if (Button == mbRight)
Button1->Perform(WM_SYSCOMMAND, 0xF006, 0);
}
//----------------------------------------------------------------------
void __fastcall TForm1::Panel1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
// Adjust both control Width and control Height by setting WParam = 0xF007
if (Button == mbRight)
Panel1->Perform(WM_SYSCOMMAND, 0xF007, 0);
}
Rodolfo
"Sky" <huangc@motic.com.cn> wrote in message
news:3f345db9@newsgroups.borland.com...
> Hi all,
>
> As everybody know we can change the postion and size when design-time,
> but how to do it when run-time, I know how to move a control, use drag and
> dock,
> but how to resize it? TIA
>
> Sky
>
>
Technical Details
Message-ID:
<3f35b738@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3f345db9@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,61501f292d40a59 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-09 20:09:37 PST From: "Rodolfo Frino" <rodolfofrino@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f345db9@newsgroups.borland.com> Subject: Re: How to resize a control when run-time Date: Sun, 10 Aug 2003 13:08:55 +1000 Lines: 135 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 203.206.24.138 Message-ID: <3f35b738@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1060484920 203.206.24.138 (9 Aug 2003 20:08:40 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!newsfeed.online.be!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail