Solved

Setting TPanel CustomAlignPosition

Posted on 2002-04-25
6
773 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now