StartPosition

EliCat

Member
Joined
Aug 29, 2002
Messages
17
Location
Netherlands
I seem to have some weird problem with the start position of one of my forms.

My forms open in this order and StartPosition

1) Mainform ... WindowsDefaultLocation
2) Reportform ... WindowsDefaultLocation and its an MDIChild with the Mainform as the container
3) Selectform ... CenterParent; this form is opened by a button on the Reportform


The way Ive set the StartPosition I would think that my select form would open in the center of the report form, but it doesnt.
The first time I open it it starts in a random position.
If I close and then reopen it starts up in the most top, left corner and each close/open procedure after that it opens at location (x,x) where x gets increasingly larger until it reaches a certain point, then it goes back to (0.0) again and starts all over.
It doesnt seem to matter to which position I drag my main+reportform (theyre not full screen) ... the procedure above happens no matter what.

The weird thing is if I set my Selectform to "CenterScreen" instead it works perfectly and always starts in the center of the screen.



Ive already bypassed the problem for this form by assigning parameters for the StartLocation (now set to Manual) before opening it and calculating them so that they open the Selectform in the center of my Mainform (instead of the Reportform), but I dont want to keep running into this problem and having to bypass it for each form I open.


Am I missing something about how CenterParent is supposed to work?
Or is it something that has to do with my Reportform being a MDI child?
 
CenterParent is for when you show dialogs modally, using the ShowDialog method of the form.

I recall it may only work when you specify the parent in the ShowDialog method, too. For example:

Code:
Dim x as frmChild = New frmChild()
x.ShowDialog(Me)

Would show the secondary form in the center of the parent form, which Im assuming the code to show it is in. Thats if the startup position property is set correctly, of course.
 
Thanks that was indeed it ....... I was using Show() instead of ShowDialog().
I changed it and it worked straight away (with of course also resetting the StartPosition of my form to CenterParent instead of Manual).


Since you werent sure if you needed to specify the parent I ran a few small tests.
I filled in both "Me" and "Me.MDIParent" and even left it blank and it makes no difference .. the form always loads in the same position now.



Since in this case it doesnt make much difference if I have my form in CenterParent or the center of my MDIParent Im now keeping it at CenterParent, but at least this little excercise has made me figure out how to bypass the parent if I want to connect its location to another form. ;)


Thanks again




And also thanks for your usefull posts all over this forum about how to work from one form on another by adjusting my constructor (I lost count of how many times you had to post the same stuff because ppl didnt bother to search the forum properly).

On that note .... about this constructor business (if you dont mind).

Ive noticed that even if I pass over the name of form1 to form2 that from form2 I cant access any objects (buttons, listboxes, etc) on form1.
At least not unless I also pass those objects into my constructor on their own.


Is this the only way to make sure you have access to not only a forms properties but also its objects (I mean without making the entire form1 public/global).

Im now already passing around 7 variables in some places and dread to see how things will look if I want to be able seperately enable/disable the various buttons on my "form1"
(Ive so far taken the easy option and gone for completely enabling/disabling form1 *g*)
 
If youre passing a variable of type Form, youll have to cast it to the actual class name (frmMain for example) before you can access members on it specific to frmMain. That or you can just have a variable of type frmMain to begin with.
 
Mmmmmmmm ........ Im sure I tried that yesterday and couldnt get it to work.
Did get it to work now though.


I must have been struggling yesterday with the forms not being in the same project (dont ask me why that is, Im only making additions to an application someone else made) and done something wrong there.


Either that or I was braindead by the time I got to that portion of the programming. ;)



Many thanks once again for making the process of learning to program with VB.NET a bit easier. ;)
 
Back
Top