Board index » delphi » Resize objects according to Form Width

Resize objects according to Form Width

I'm trying to resize a series of objects according to the form's width.  For
instance, I have a panel, several buttons and an image.  If the user resizes
the form, or if they maximize or minize the form, I want to resize these
objects according to the form's width (and height).  I have created the form
in a normal fashion.  However, when run, the form is initially maximized
(the form was not created maximized).  When I try to execute the following
code inside the form's OnShow Event:
     Image1.Left := Width div 2;
     Panel1.Width := 192 + (Image1.Left - 88);

It doesn't move the Image's left edge.  If I place this code inside a
button, when I press the button, it works file.

Anyone how where I should place this code to get it to work?

Thanks,
Jesse

 

Re:Resize objects according to Form Width


In article <6b0ofe$1t...@news9.ispnews.com>, Jesse Castleberry
<D...@iThink.net> wrote

Quote
>If the user resizes
>the form, or if they maximize or minize the form, I want to resize these
>objects according to the form's width (and height).
>Anyone how where I should place this code to get it to work?

Have you tried the form's OnResize event handler?

--
Gary Jones (Replace "zappa" with "demon" in e-mail address)
PGP public keys available from servers
RSA Key ID: 0x6AFBEAA1
DSS/Diffie-Hellman Key ID: 0x11EAE903

Re:Resize objects according to Form Width


Quote
Jesse Castleberry wrote...

|I'm trying to resize a series of objects according to the form's
width.  For
|instance, I have a panel, several buttons and an image.  If the user
resizes
|the form, or if they maximize or minize the form, I want to resize
these
|objects according to the form's width (and height).  I have created
the form
|in a normal fashion.  However, when run, the form is initially
maximized
|(the form was not created maximized).  When I try to execute the
following
|code inside the form's OnShow Event:
|     Image1.Left := Width div 2;
|     Panel1.Width := 192 + (Image1.Left - 88);
|
|It doesn't move the Image's left edge.  If I place this code inside a
|button, when I press the button, it works file.
|
|Anyone how where I should place this code to get it to work?

I've had a similar experience with getting a form's size. It seems
that in the OnCreate() and OnShow() events - which both fire *before*
the form actually becomes visible - the form  still has the size as it
was left in the IDE, despite all settings of wsMAXIMIZED. (you can
check that easily by setting a breakpoint in OnShow())
The only hack I could think of then, was to start a timer in
OnCreate(), and do all resizing in the OnTimer() event.
I'm sure there must be more elegant ways...

Regards,
Dirk Claessens
______________________________________________
Home   : <dirk.claess...@village.uunet.be>
Office : <dirk.claessens...@belgium.agfa.com>
Nothing will come of nothing.
Dare mighty things. (William Shakespeare)
______________________________________________

Re:Resize objects according to Form Width


Quote
>Have you tried the form's OnResize event handler?

Yes, I guess the problem is that the user really hasn't resized the form.
The system did.  I create the form in the regular size, but when the form is
ran, it is automatically "maximized."  I want it to be automatically
maximized.  I can't work on the form in this format, however, because the
form may be displayed on a 640x480 screen, 800x600, or higher, so the size
may vary.

Jesse

Re:Resize objects according to Form Width


Quote
>The only hack I could think of then, was to start a timer in
>OnCreate(), and do all resizing in the OnTimer() event.
>I'm sure there must be more elegant ways...

Creative...But you're right, there's got to be a more elegant way.  Question
is, what is it??

Jesse

Re:Resize objects according to Form Width


Quote
Jesse Castleberry wrote:

> >Have you tried the form's OnResize event handler?

> Yes, I guess the problem is that the user really hasn't resized the form.
> The system did.  I create the form in the regular size, but when the form is
> ran, it is automatically "maximized."  I want it to be automatically
> maximized.  I can't work on the form in this format, however, because the
> form may be displayed on a 640x480 screen, 800x600, or higher, so the size
> may vary.

> Jesse

A radical solution would be to force the max size to 640x480 using the
following message :
Procedure TForm1.WMGetMinMaxInfo(Var Msg : TWMGetMinMaxInfo);
Begin
        Msg.MinMaxInfo^.ptMinTrackSize.x:=640;
        Msg.MinMaxInfo^.ptMaxTrackSize.x:=640;
        Msg.MinMaxInfo^.ptMinTrackSize.y:=480;
        Msg.MinMaxInfo^.ptMaxTrackSize.y:=480;
End;

And in order to know what's the real size, try to intercept the WM_SIZE
message.

Re:Resize objects according to Form Width


Quote
Jesse Castleberry wrote:

> >The only hack I could think of then, was to start a timer in
> >OnCreate(), and do all resizing in the OnTimer() event.
> >I'm sure there must be more elegant ways...

> Creative...But you're right, there's got to be a more elegant way.  Question
> is, what is it??

> Jesse

If you already tried to place the code in the onResize event, then try
to place it in the onPaint event. You'll loose a bit of time everytime
the form repaints but it's worth a shot.

--
Hope this is what you were looking for.
+-------------------------------------------+
|  Jorge Santos                             |
|  mailto:san...@net-lynx.com               |
|  http://www.net-lynx.com/users/~santos    |
+-------------------------------------------+

Re:Resize objects according to Form Width


Quote
Jesse Castleberry wrote:
> I'm trying to resize a series of objects according to the form's width.  For
> instance, I have a panel, several buttons and an image.  If the user resizes
> the form, or if they maximize or minize the form, I want to resize these
> objects according to the form's width (and height).  I have created the form
> in a normal fashion.  However, when run, the form is initially maximized
> (the form was not created maximized).  When I try to execute the following
> code inside the form's OnShow Event:
>      Image1.Left := Width div 2;
>      Panel1.Width := 192 + (Image1.Left - 88);

> It doesn't move the Image's left edge.  If I place this code inside a
> button, when I press the button, it works file.

> Anyone how where I should place this code to get it to work?

const  PM_FIXSIZE = WM_USER + 1234;

type TForm1 = class....
  procedure PMFixSize(var Message : TMessage); message PM_FIXSIZE;

FormShow:
  PostMessage(Handle, PM_FIXSIZE, 0, 0);

PMFixSize:
  - Do whatever.

Regards,

Erik.

--
Development of applications and drivers for Windows 95 and NT.
Go visit http://www.POBoxes.com/Sperling for some free source!
Check out Delphi Bug Lists at http://www.POBoxes.com/DelphiBugList
PGP public key available at http://www.POBoxes.com/Sperling/pgpkey.txt

Erik Sperling Johansen, Sperl...@POBoxes.com (DeBug Team; checker, monitor)

Re:Resize objects according to Form Width


Jesse -

Why not put all the components you want to resize on panels that you have
aligned to the form in some fashion?  I have a button panel on the bottom of
almost every window, with a panel on that panel that is aligned to the right.  I
then put the OK and Cancel buttons on that panel.  When the form is resized,
those two buttons are always in the lower right corner.  By making panels (or
group boxes) align top, left, right, bottom, or client, you can get all kinds of
cool effects.

--
Clayton Neff
Software Project Leader
The Personal Marketing Company, Inc.
11843 West 83rd Terrace
Lenexa, KS  66214
(913)492-0322
clay...@tpmco.com

Re:Resize objects according to Form Width


Create a procedure to do the screen refreshing and then point onactivate
and onresizing to it. You should be okay then..

-Dave

(sorry I couldn't quote the origional letter but my email program
wouldn't let me)...

Re:Resize objects according to Form Width


Try putting the code in the OnResize event of the form.

Re:Resize objects according to Form Width


Quote
In article <6b33n7$2j...@news4.ispnews.com> "Jesse Castleberry" <D...@iThink.net> writes:
>From: "Jesse Castleberry" <D...@iThink.net>
>Subject: Re: Resize objects according to Form Width
>Date: Sun, 1 Feb 1998 19:23:57 -0500
>>Have you tried the form's OnResize event handler?

>Yes, I guess the problem is that the user really hasn't resized the form.
>The system did.  I create the form in the regular size, but when the form is
>ran, it is automatically "maximized."  I want it to be automatically
>maximized.  I can't work on the form in this format, however, because the
>form may be displayed on a 640x480 screen, 800x600, or higher, so the size
>may vary.
>Jesse

You don't say what version of Delphi you're running.  In D3 you've got the
TWinControl.ScaleBy facility.  This scales a control and all its children.
In my experience this solution is not elegant.  On a form with few controls
I've found it more elegant to start the application normalized and then
to rescale the bits and pieces in an OnResize event.  Alternately, define the
creation size in variables and in the OnCreate event of the form, do the
resizing.

HTH,
         John.

Re:Resize objects according to Form Width


Jesse Castleberry <D...@iThink.net> wrote in article
<6b0ofe$1t...@news9.ispnews.com>...

Quote
> I'm trying to resize a series of objects according to the form's width.
For
> instance, I have a panel, several buttons and an image.  If the user
resizes
> the form, or if they maximize or minize the form, I want to resize these
> objects according to the form's width (and height).  I have created the
form
> in a normal fashion.  However, when run, the form is initially maximized
> (the form was not created maximized).  When I try to execute the
following
> code inside the form's OnShow Event:
>      Image1.Left := Width div 2;
>      Panel1.Width := 192 + (Image1.Left - 88);

Use the OnResize event.
Also, try using the form's ClientWidth and ClientHeight .
(Gives you the area inside the form's frame and scrollbars.)

Best wishes,

Michael Caracena
carac...@henge.com

Re:Resize objects according to Form Width


Quote
>Use the OnResize event.
>Also, try using the form's ClientWidth and ClientHeight .
>(Gives you the area inside the form's frame and scrollbars.)

Tried that.  Problem is when the form is initially run, it's not "resizing"
the form.  Or at least, it doesn't execute the OnResize event.

Re:Resize objects according to Form Width


On Sat, 31 Jan 1998 21:59:25 -0500, "Jesse Castleberry"

Quote
<D...@iThink.net> wrote:
>I'm trying to resize a series of objects according to the form's width.  For
>instance, I have a panel, several buttons and an image.  If the user resizes
>the form, or if they maximize or minize the form, I want to resize these
>objects according to the form's width (and height).  I have created the form
>in a normal fashion.  However, when run, the form is initially maximized
>(the form was not created maximized).  When I try to execute the following
>code inside the form's OnShow Event:
>     Image1.Left := Width div 2;
>     Panel1.Width := 192 + (Image1.Left - 88);

>It doesn't move the Image's left edge.  If I place this code inside a
>button, when I press the button, it works file.

>Anyone how where I should place this code to get it to work?

>Thanks,
>Jesse

Hi Jesse,

The solution to your problem is to create a procedure of your form
which will size and place your controls the way you want relative to
the forms Height and Width, and to call it from both the OnResize and
OnActivate events of the form.

You can eliminate the unnecessary overhead of resizing and re-placing
the controls each time the window is activated without being resized,
by using a global flag to make sure the OnActivate event calls the
said procedure only the first time it is entered.

If you need a sample code, just send me an e-mail.
Pierre Gemis

Go to page: [1] [2]

Other Threads