Top Form has focus.... HOW?

vbMarkO

Centurion
Joined
Aug 19, 2005
Messages
157
On form load of main Form a file is checked for if the file exists and contains certain data then a 2nd FOrm is opened...

WHat I am needing to know is 2 things....

1. How do I make it so the Form2 is the one that has the focus and not Form1

2. Also, How do I make Form2 open dead center of Form1?


vbMarkO
 
For #2, you have two choices. One, set Form2's startup position property to CenterParent (via designer) and set the form's parent as the instance of Form1 (via code). Two, you can do the math out yourself, but positioning forms before they are shown has a tendency to work inconsistently at best and positioning them after they are shown looks unprofessional.

For #1, I haven't tested this. I'm just throwing it out there. You could explicitly show both forms (possibly in Form1's load event) and then set focus to Form2.
 
I believe setting focus in the form load event will not work because the Activated event is triggered after the load event, and that will bring focus back to the main form. So based on this assumption, if you declare Form2 publicly, then initialise it only if you need to, in the Activated event of Form1 check if Form2 = null if not the set focus to it.You probably also need a boolean to check its the first call to activated so that it doesn't keeep showing Form2 everytime you activate Form1. This all sounds abit messy, theres probably a better solution, but I can't think of one.
 
Is Form2 modal or modeless? If Form2 can be modal you can always just do a _form2.ShowDialog(Me) from within Form1 somewhere.
 
Back
Top