Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by UCM

UCM

>-)

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted (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 by divil

UCM

>-)

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted (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 by divil

UCM

>-)

Posted (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 by UCM

UCM

>-)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...