UCM Posted February 19, 2003 Posted February 19, 2003 (edited) How to have 1 instance of 2x forms and switch between them... Please see posts below.... * Attachment deleted by UCM * please see post below, thank you.... Edited February 19, 2003 by UCM Quote UCM >-)
*Experts* Bucky Posted February 19, 2003 *Experts* Posted February 19, 2003 I downloaded and ran it and nothing of what you mentioned happened. You may want to create a new project and try again. This was one thing I noticed, however. When you are "switching" from Form1 to Form2, you need to declare a NEW instance of Form2 before you can show and hide it. This can be done in the declare (Dim myForm2 As New Form2). The same holds true for the myForm1 variable on Form2. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
UCM Posted February 19, 2003 Author Posted February 19, 2003 (edited) Crap, wrong exapmle lol... sorry, I uploaded the wrong example.... the example I have the above issue with is the one where I use a module to control both instances of the forms.... Thanx for your input on the above example though, that helps with it.... Edited February 19, 2003 by divil Quote UCM >-)
*Experts* Bucky Posted February 19, 2003 *Experts* Posted February 19, 2003 Before I even opened the project, I had a hunch about what was wrong, because it's a common problem that I myself have made. Since a Windows application needs to have a continuous message pump, and a window to handle it, you cannot use a simple Form.Show() to show a new instance of a form when your application starts from Sub Main. Instead, you need to tell the application to send Windows messages to a specific form. To do this, use the Application.Run() method. After the form closes (and is destroyed and its message pump destroyed), the code will return to the Sub Main and continue on the next line of code. This is what you currently have: Public Sub Main() myForm1.Show() myForm1.TextBox1.Focus() End Sub This is what you need: Public Sub Main() Application.Start(myForm1) ' Put the code to focus TextBox1 in the Form's load event End Sub The rest of the code in the module will work fine. I should point out that it is better OOP practice to shun the use of modules and instead use shared (aka static) method of classes. You may want to try this in the future. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
UCM Posted February 19, 2003 Author Posted February 19, 2003 (edited) How would I apply the good OOP practice you're mentioning to the first example I uploaded before in error? In case you deleted it, here it is again... btw, I would much rather avoid using modules but to get it with just 1 instance of each form, I wound up having to use the module....Of course, I fyou can help me get the below example to work without a module then you will of made my week :)accessmultipleformsincodewithoutamodule.zip Edited February 19, 2003 by divil Quote UCM >-)
*Gurus* divil Posted February 19, 2003 *Gurus* Posted February 19, 2003 You _never_ need to use modules. Your Sub Main can go in any class you like, as long as you make sure it has the Shared modifier in its declaration. Also, please don't include binaries in attachments. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
UCM Posted February 19, 2003 Author Posted February 19, 2003 (edited) Any idea how I can make the above example "accessmultipleformsincodewithoutamodule.zip" work with just 2 forms and no modules or sub mains? I thought I did it once before, but when I looked at the old example I put in moff balls, it haed a module run with sub main, oyy.... I'll use a sub main if I have to, bout I would like to not have to use it.... All I need is just 1x instance each of 2 different forms and be able to call each other form from the other... btw, VolteFace helped me get this idea to work in This Thread but we're still using a module... I would love to ditch the module altogeather, but if that isn't going to acheive the desired result of each form keeping their values and contents then I'll settle for the module and build my project around that... Thank you everyone very much for your help on this, I really appreciate it :-) Edited February 19, 2003 by UCM Quote UCM >-)
*Experts* Nerseus Posted February 21, 2003 *Experts* Posted February 21, 2003 Check out this thread -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
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.