Solved

Setting TPanel CustomAlignPosition

Posted on 2002-04-25
6
782 Views
Last Modified: 2012-05-04
All -

I have a TPanel sitting in the center of a Tabsheet. When the application is maximized and the tabsheet goes max, the panel fails to stay centered within the tabsheet.

I think it has something to do with the alignment property. So I changed the setting to be 'alcustom' and tried to set the code to do this:

procedure TfrmMDIMain.CustomAlignPosition(Control: TControl; var NewLeft,
  NewTop, NewWidth, NewHeight: Integer; var AlignRect: TRect;
  AlignInfo: TAlignInfo);
begin
  begin
    NewLeft := 0;
    NewTop := Panel3.BoundsRect.Bottom;
    NewHeight := ClientHeight - Panel3.BoundsRect.Bottom;
  end;
end;

I'm really unsure on how to do this, but there must be a method to keep the TPanel centered no matter what condition the applciation is in.

Examples, please.

TIA -

RB
0
Comment
Question by:routerboy309
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 6969770
Another method would be to use to Anchors property of the TPanel. Anchor the sides according to the effect you want. Example, anchor all sides if you want it to grow with the parent control. If you dont want it to grow, Anchor the sides, and use constraints to prevent the growing, and retain its size.

Shane
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6970566
Easiest way.

In the OnResize method for the TTabSheet, put the following code (Assuming your panel is called Panel1).

Panel1.Top := (TabSheet1.ClientHeight - Panel1.Height) div 2;
Panel1.Left := (TabSheet1.ClientWidth - Panel1.Width) div 2;

That will ensure it's always centered.

Cheers!

Stu
0
 

Author Comment

by:routerboy309
ID: 6971200
Stu -

I like that method. What about if the panel is slightly off set (by choice)? Is there an easy way to control that?

RB
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 6

Accepted Solution

by:
Stuart_Johnson earned 50 total points
ID: 6971223
The only way I could think of doing this would be to pass it the offsets.  For instance:

procedure TForm1.FormResize(Sender: TObject);
const
  OffsX = 5;
  OffsY = 10;

begin
  Panel1.Top := ((TabSheet1.ClientHeight - Panel1.Height) div 2) - OffsY;
  Panel1.Left := ((TabSheet1.ClientWidth - Panel1.Width) div 2) - OffsX;
end;

Those constants could be globablly declared if you really needed to.

For historical info only, this is the way you used to have to center forms in VB :)  Ah, Delphi, is there anything it can't do? :)

Stu
0
 

Author Comment

by:routerboy309
ID: 6971309
Thanks! That works. Tweaked a little to get the right X/Y settings.

RB
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6971314
Excellent.  Glad that worked for you :)

Thanks for the points and the grading!

Cheers,

Stu
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Communication Between RC4 Delphi <-> PHP 3 115
Delphi: ForceDirectory plain function 7 33
RESTRequest Parameter 4 31
DBCtrlGrid, Delphi, Scroll 8 14
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question