Solved

exact positioning of fomr2 on form1

Posted on 1998-03-01
2
239 Views
Last Modified: 2010-04-06
hi,

I got 2 forms, And I need to load Form2 exactly in the center of form1. So that both forms center is in the same position, any ideas?
bye
0
Comment
Question by:hellfire052497
  • 2
2 Comments
 
LVL 5

Accepted Solution

by:
julio011597 earned 50 total points
ID: 1359944
In Form2 code:

--//--
implementation

uses
  Form1Unit;

procedure TForm2.Form2Create(Sender: TObject);
var
  CenterX, CenterY: Integer;
begin
  with Form1 do begin
    CenterX := Left + Width div 2;
    CenterY := Top + Height div 2;
  end;
  with Self do begin
    Left := CenterX - Width div 2;
    Top := CenterY - Height div 2;
  end;
end;
--//--

This will create Form2 centered on Form1.

HTH, julio
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1359945
As you can see, i put the code inside the OnCreate handler of Form2, but you could put it anywhere needed: OnActivate, OnShow, or even attach it to a button, so that, when you click it, Form2 gets centered on Form1.
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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 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

14 Experts available now in Live!

Get 1:1 Help Now