Solved

Centering child forms

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 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