Solved

Centering child forms

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

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

24 Experts available now in Live!

Get 1:1 Help Now