Solved

Centering child forms

Posted on 2004-08-19
3
214 Views
Last Modified: 2012-08-13
Hi kids!  It's your favorite bitter programmer again. :)

My latest excursion is an attempt to center one form on top of another.  Since the MS supplied Messagebox blows, I created a form that does the same thing (but looks appropriately cool) liike so:

Function NetMsgBox(Message as String,Title as String, Caption as String, BoxType as Integer) as Boolean

When this opens up I'd like it centered over the parent form.  Problem is, determining the parent form from the load of this one.  In the form_load for the msgbox I attempted this:

        XCoord = (Me.ParentForm.Width / 2) - (Me.Width / 2)
        YCoord = (Me.ParentForm.Height / 2) - (Me.Height / 2)

It seems logical but 'parentform' is not defined.  Apparently this property is for MDI applications, which mine isn't.  I could pass a reference from the calling form but I'd rather not add another parameter to the function.

Is there an easy way of determining the screen area of the parent or calling form or the entire screen itself?  Should I just pass the reference from the parent through a global variable?  Or is there some property of method I'm missing that makes this simple?

Thanks!
0
Comment
Question by:MIKEV
[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
3 Comments
 
LVL 25

Assisted Solution

by:RonaldBiemans
RonaldBiemans earned 50 total points
ID: 11841395
When you open your form use the owner property

dim f as new yourform
f.owner = me
f.show

in your yourform you can do

 XCoord = (Me.owner.Width / 2) - (Me.Width / 2)
        YCoord = (Me.owner.Height / 2) - (Me.Height / 2)



0
 
LVL 27

Accepted Solution

by:
planocz earned 200 total points
ID: 11841447
with your message box form set the start postion to centerparent
and then have have form be  
e.i....

start postion  = centerparent
MYMessageForm.ShowDialog()
0
 

Author Comment

by:MIKEV
ID: 11841549
Ron:  The caller function is within a module and 'Me is not valid in a module'.

Planocz:  That's the one, thanks!
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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