Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3219134
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:36:35+00:00 2026-05-17T15:36:35+00:00

I have a wide TPanel with several buttons on it (essentially a tool bar).

  • 0

I have a “wide” TPanel with several buttons on it (essentially a tool bar). All the buttons have Align=Left. I have created a function which will resize the buttons to the same size and calculate the width of them so they fill the entire TPanel. I call this function in the OnResize event handler of the TPanel.

procedure ScaleButtonsOnPanel;
var i: Integer;
begin
  for i:=0 to mPanel.ControlCount-1 do begin
      mPanel.Controls[i].Width := round(mPanel.width/mPanel.ControlCount-1)
  end;
end;

The problem is if I minimize and then restore the form the layout of the buttons change from the design layout.

Can anyone offer a solution to having buttons on a panel which can be resized but maintain the design time order (in terms of left to right placement) ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:36:35+00:00Added an answer on May 17, 2026 at 3:36 pm

    I do not really see your problem. But of course, you must set the position of the buttons, not only their size.

    procedure TForm1.Panel1Resize(Sender: TObject);
    var
      i: Integer;
      btnWidth: integer;
    begin
      btnWidth := Panel1.Width div Panel1.ControlCount;
      for i := 0 to Panel1.ControlCount - 1 do
      begin
        Panel1.Controls[i].Left := i * btnWidth;
        Panel1.Controls[i].Width := btnWidth;
      end;
    end;
    

    This works very well.

    See https://privat.rejbrand.se/panelresize.wmv.

    OK, now I see. I think the alLeft is actually your problem. Controls with the same align tend to change their order. This is a well-known Delphi annoyance. Do it like I do above, instead. Just make sure that you go through the buttons in the right order. If you cannot rely on the ordering of Panel1.Controls, then you can do like this: Set the Tag property of each toolbar button to its position (0, 1, …) in the toolbar then do

    procedure TForm1.Panel1Resize(Sender: TObject);
    var
      i: Integer;
      btnWidth: integer;
    begin
      btnWidth := Panel1.Width div Panel1.ControlCount;
      for i := 0 to Panel1.ControlCount - 1 do
      begin
        Panel1.Controls[i].Left := Panel1.Controls[i].Tag * btnWidth;
        Panel1.Controls[i].Width := btnWidth;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have site wide default settings for all jQuery validation uses on
I have a site in rails and want to have site-wide settings. One part
I have a system-wide manual reset event that I create by doing the following:
You'll have to forgive my ignorance, but I'm not used to using wide character
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a wide flash movie (to fit in more screen resolution). I would
I have a wide char string is Lhao123--我的上网主页, and it must be encoded to
I have a wide screen and I would like to see the code I
Does IDEA have module wide error analysis like R#'s solution wide analysis? I'd like
I have noticed an undesirable behavior with .net winforms applications. I have a wide

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.