Solved

Setting TPanel CustomAlignPosition

Posted on 2002-04-25
6
765 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

18 Experts available now in Live!

Get 1:1 Help Now