Solved

Centering child forms

Posted on 2004-08-19
3
213 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sql server insert 13 46
Expression Evaluater 3 45
VB.Net. Reading xml value 6 36
VS 2015 is giving [No relevant source lines] 2 38
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…

740 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