Solved

Setting TPanel CustomAlignPosition

Posted on 2002-04-25
6
810 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month6 days, 11 hours left to enroll

623 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