RE: Centering Owner Forms
"Glenn B. Lawler" <[email protected]> Fri, 15 Aug 2003 14:52:31 -0500
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <[email protected]> |
Joe, > I have a process that upon the main forms creation, it also > instantiates another child form but does not show it. This hidden > form's Position property is set to poOwnerFormCenter. This hidden > form is only shown as necessary, then hidden. It does not get closed > or free'd until the main form is closed. > > However, what is happening is if I move the main form, when the child > form gets shown, it's still using the old parent form position for > it's positioning. > > How do I get theis child form to recognize the new position of the > parent form so it's poOwnerFormCenter is still an accurate setting? Center the form yourself before making it visible. Here a procedure I wrote to do this: procedure CenterFormOnForm(const NewForm,MainForm: TForm); begin if NewForm.WindowState<>wsNormal then exit; NewForm.Top:=MainForm.Top + ((MainForm.Height - NewForm.Height) div 2); If NewForm.Top < 0 Then NewForm.Top:=0; NewForm.Left:=MainForm.Left + ((MainForm.Width - NewForm.Width) div 2); If NewForm.Left < 0 Then NewForm.Left:=0; end; When you call this, you'll have to typecast the form like this: CenterFormOnForm(TForm(MyNewForm),TForm(MainForm)); HTH, Glenn Lawler ------------------------ Yahoo! Groups Sponsor ---------------------~--> Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511 http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/i7folB/TM ---------------------------------------------------------------------~-> Delphi VCL Top Sites! http://www.sandbrooksoftware.com/TS/TS2/Components.shtml --------------------------------------------------------------- Unsubscribe:[email protected] List owner:[email protected] --------------------------------------------------------------- Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/