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
We're building a kiosk app that will have a fairly wide deployment. The app
I have site wide search where I put the search results into several Rad
You need to have several 200px wide DIVs (.item) inside a 620px wide DIV
I have wide bar-shaped DIV in my HTML and want to put 2 groups
I have a site wide JS, which creates listeners for various events, but in
I have a wide flash movie (to fit in more screen resolution). I would
I have a 1px wide by 35px high image, that I set as background
I have enabled site-wide Django caching , but the third-party apps I am using
Intel's 32-bit processors such as Pentium have 64-bit wide data bus and therefore fetch

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.