views:

106

answers:

3

Hello everybody,

I am making a program in vb.net (visual basic) that has two forms. I have one as a sort of "main" base which will be behind everything. Then I have another additional form which is suppose to go on top of the "main" form. Well I get this to work when I show both of the forms, but I want the smaller (additional) form to be centered onto the main form. If you want an easier sense of it, its a small box in a big box. (all centered and aligned). Does anyone know how to do this?

Thanks

+1  A: 

FormStartPosition.CenterParent -- a .NET enumeration described here : http://msdn.microsoft.com/en-us/library/system.windows.forms.formstartposition.aspx

Jay
Yea I do that for my "small" form and it doesn't seem to align...
Kevin
**Is** this MDI, or not?
Jay
It's not... If I set it to MDI it looks a bit weird and messes up my design
Kevin
MDI is meant to used where you have a parent-child relationship. As you described, the "main base" seemed to be the parent and the "small" form the child. In an MDI design, the child cannot be placed outside of the parent, and therefore keeps things relatively tidy, and the user can navigate easily, since they know all child windows of the parent form are located within the parent form. The design you seem to be seeking is somewhat unusual for modern UI design, but can be achieved by setting the x, y, top and left properties of the child form directly. See my answer below for such a link.
Topdown
see new answer...
Jay
A: 

It sounds like you're looking for a MDI interface for your form presentation. If so, then could you try using:

childForm.StartPosition = FormStartPosition.CenterParent;

This will centre it on the screen. If not, you might want to try centering it explicitly as shown here

Topdown
A: 

I'm assuming that the main form creates the child form.

When main form (A) creates small form (B), it should give B a reference to itself (which is to say that B should accept a constructor parameter of type Form, called something like backgroundForm, and pass A).

Now B can set its position in the OnLoad event as follows:
x-coord: the x position of A plus 1/2 the width of A minus 1/2 the width of B
y-coord: the y position of A plus 1/2 the height of A minus 1/2 the height of B

Furthermore, B can subscribe to events in A, such as when the window is moved or resized.

Jay
Do you have an example coding..? It might seem kind of confusing to me..
Kevin