Solved

Centering child forms

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

17 Experts available now in Live!

Get 1:1 Help Now