vbMarkO Posted August 25, 2006 Posted August 25, 2006 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 Quote Visual Basic 2008 Express Edition!
Leaders snarfblam Posted August 25, 2006 Leaders Posted August 25, 2006 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. Quote [sIGPIC]e[/sIGPIC]
Cags Posted August 25, 2006 Posted August 25, 2006 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. Quote Anybody looking for a graduate programmer (Midlands, England)?
mskeel Posted August 27, 2006 Posted August 27, 2006 Is Form2 modal or modeless? If Form2 can be modal you can always just do a _form2.ShowDialog(Me) from within Form1 somewhere. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.