Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting TPanel CustomAlignPosition

Posted on 2002-04-25
6
Medium Priority
?
816 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

721 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