Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

center a form within another form

Posted on 1998-08-18
5
Medium Priority
?
171 Views
Last Modified: 2010-04-04
I have small dialog/form that is started from the main form. I want this small form to always come up centered within the main form no matter where it is on the screen. How can I do this in Delphi 4.0?
0
Comment
Question by:Kmiller
[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
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
Matvey earned 200 total points
ID: 1337202
I doubt there is some automatic method for it. There's nothing to it - just set the dialog form position according to the other form position:

frmDialog.Left := frmMain.Left + frmMain.Width div 2 - frmDialog.Width div 2;
frmDialog.Top := frmMain.Top + frmMain.Height div 2 - frmDialog.Height div 2;

-Then show it.

c u, Matvey
0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1337203
I use something like this in the FormShow method on the dialog form (where frmMain is the main form):

  (* Center dialog on mainform *)
  PWidth := frmMain.Width;
  PHeight := frmMain.Height;
  Left := ((PWidth - Width) Div 2) + frmMain.ClientOrigin.X;
  Top := ((PHeight - Height) Div 2) + frmMain.ClientOrigin.Y;

0
 
LVL 7

Expert Comment

by:BlackMan
ID: 1337204
Ok Matvey, you were the fastest! But mine works better (I guess)with MDI forms!
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337205
In the main form that sits behind not the dialog form, enter this in OnShow...

procedure MainForm.OnShow......
begin
  DialogForm.Top := ( MainForm.Height div 2 ) - ( DialogForm.Height div 2 );
  DialogForm.left := ( MainForm.Width div 2 ) - ( DialogForm.Width div 2 );
end;

That's all you need to do! ;)

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337206
Wow, you were very fast... ;)

Matvey did you see the comp I sent you the other day? Is it cool?

Regards,
Viktor Ivanov
0

Featured Post

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.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

610 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