Board index » delphi » Resize objects according to Form Width

Resize objects according to Form Width

Hello Pierre,

Quote

>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

If the code isn't too big, it might help a lot of people to post it here.
According to my experiences this is a big problem for many people, so
brainstorming about it together might help all of us.

Bye!

Arjan
=========================================================
Arjan van de Logt author of Yer Winlogo and other utils.
E-mail Arjan_van_de_L...@wxs.nl

Quote
>(Replace all underscores [_] with dots [.] to reply!!!)

http://www.tomb.demon.nl
=========================================================
 

Re:Resize objects according to Form Width


On 2 Feb 1998 07:37:00 -0700, cn...@primenet.com (Clayton Neff) wrote:

Quote
>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.

Hi,

It's a solution, allright and it works fine too.
I'm also using it in some accasions, but it has one disadvantage:
Your applications become bigger when you use more forms.
So, I just do a lot of work in the onResize event. It saves kB's for the user
(to download if it's spread through the Internet). But when you do use panels
anyway, it's allways easy to take a look to use them also the way you do, it
saves a lot of programming.

Bye!

Arjan

=========================================================
Arjan van de Logt author of Yer Winlogo and other utils.
E-mail Arjan_van_de_L...@wxs.nl

Quote
>(Replace all underscores [_] with dots [.] to reply!!!)

http://www.tomb.demon.nl
=========================================================

Re:Resize objects according to Form Width


On Mon, 09 Feb 1998 17:48:53 GMT, Arjan_van_de_L...@wxs.nl (Arjan)
wrote:

Quote
>If the code isn't too big, it might help a lot of people to post it here.
>According to my experiences this is a big problem for many people, so
>brainstorming about it together might help all of us.

>Bye!

>Arjan

Well, here it goes. For this minimal example, I am working only with
horizontally (Width and related stuff).
I have only one form, with only one button on it. The form shows
initially maximized. The code ensures the form does not shrink below
some size, and adjusts the width of Button1 so that it uses all the
form's ClientWidth, with 8-pixel left and right margins (Note that
Button1.Left and Button1.Top are 8 and get never changed)

unit Unit1;

interface
....
type
  TForm1 = class(TForm)
   ...
  private
    { Dclarations prives }
    procedure MyResize;
  public
    { Dclarations publiques }
  end;

var
  Form1: TForm1;

implementation
...
var
   xbFirstResize : Boolean;
procedure TForm1.MyResize;
// Could also be implemented as the code for the OnResize
// event. Then, the code in OnActivate would call FormResize...
var
   iHorz : Integer;
begin
   // Assign adjust values
   iHorz := Width-ClientWidth;
   // Make sure form keeps a minimum size
   if Width < 75 {Arbitrary value} + iHorz
      then Width := 75 + iHorz;
   // Horizontally size Button1
   Button1.Width := ClientWidth - 16;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   xbFirstResize := True;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
   // This code needed because WindowState is wsMaximized
   if not xbFirstResize
      then exit;
   MyResize;
   xbFirstResize := False;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
   MyResize;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   Close;
end;

end.

Pierre Gemis

Re:Resize objects according to Form Width


In comp.lang.pascal.delphi.components.usage Jesse Castleberry <D...@iThink.net> wrote:
:>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.
Why don't you call your onresize procedure at the end of your oncreate, I
usually do that to get my forms to look ok and it never failed me before.

Go to page: [1] [2]

Other Threads