The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

VB6 and forms

i had posted earlier about how our customers seem to find our apllication frozen and they can get back the control by pressing alt + F4.

after much head scratching and with help of an utility, we found that the X and Y co-ordiantes for the form were out of range of the screen and because of that form would not be visible. and since it was modal, the app would seem to be frozen.

we have a routine that centers the form  by getting the screen width and height. and in some case this routine seems to be mis firing.

we use some thing like

    Frm.Move (Screen.Width - Frm.Width) / 2 ,(Screen.Height - Frm.Height) / 2

is there a better way to center the form?  other than setting the property startupinposition?

thanks
dan

Wednesday, June 14, 2006
 
 
VB6 forms have a StartUpPosition Property,

If all you want is to ensure the form opens on the center of the users screen, set the StartUpPosition Property in the properties window for the form to "2-CenterScreen".

Personally, I prefer to use "1-CenterOwner" as that positions newly opened modal forms on top of the form that opened it.

Hope that helps
Bob Stelman Send private email
Wednesday, June 14, 2006
 
 
Of course, after submitting the suggestion I noticed that you prefer not to use StartUpPosition property. Why do you not want to use it?
Bob Stelman Send private email
Wednesday, June 14, 2006
 
 
- Set FormX's StartupPosition to 2 - CenterScreen in design mode
- Save your project
- 2 months later, again work on this project
- open the project
- move FormX out of the way of something in design mode
- Oops! You have set its StartupPosition to 0 - Manual!

This is why I have a CentreOn routine in my utils library...
Larry Lard Send private email
Thursday, June 15, 2006
 
 
Go with the option CenterOwner for modal forms. Anything else should support multiple monitors which the above solutions do not. Do not use the VB Screen object unless you know the rest of the app is also on the primary monitor.

Look at these API's:
GetMonitorInfo
MonitorFromWindow

I've created a simple function with the following definition to center a form on its parent forms monitor:
Public Sub CenterForm(frm As Form, frmParent As Form)

If you need more help, let me know.
Adrian
Thursday, June 15, 2006
 
 
thank you for thr tips.
 i learnt some thing new and was able to implement a cleaner method of centering form on screen.

at the same time, i realised one more aspect. suppose if i have to center a child form to a parent form, whats the best way to take care of it?

as of now we are finding out the width,left etc of parent form and the child form and then move the child form accordingly.

is there a cleaner way for this?

thanks
dan

Friday, June 16, 2006
 
 
> is there a cleaner way for this?

I let the child form handle positioning itself over a center-point passed in as a parameter to the form. I do this because we have forms in ActiveX control projects that need to position themselves over the parent form which resides in the main EXE. You hit problems passing form objects between projects.
Adrian
Friday, June 16, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz