?
Solved

Showing a vb.net form

Posted on 2003-02-21
6
Medium Priority
?
271 Views
Last Modified: 2011-09-20
In vb 6 I can show a form using:
   Form1.show

Or I can show the form modally using:
   Form1.show vbModal

In vb.net that does not work unless I first dim a new form then show:
  Dim MyForm1 as New Form1()
  MyForm1.Show()

However, I can't continue Dim'ing the form as I create multiple copies of the form.  I just want to dim it once and show or hide in the future.

Also need to consider when the user exits the form by clicking the "X" in the control box.

I am new to vb.net and so I hope this is an easily solved problem.  vb.net seems more complicated and verbose than vb 6?

Thanks for the help.
0
Comment
Question by:EYoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 2

Expert Comment

by:Drifter88zxtW
ID: 7997732
Make the MyForm1 a Module Level Variable
and instnsiate it in the Form_Load event.

MyForm1.ShowDialog will show the form modaly.

Checking on determing how form is closed
0
 
LVL 2

Expert Comment

by:Drifter88zxtW
ID: 7997757
All I could find was that it that the UnloadMode has no equivalent in .net

But im sure there is some way. But I dont know it =)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vxconchangestoformobjectinvisualbasicnet.asp
0
 
LVL 7

Author Comment

by:EYoung
ID: 7999428
How do I "Make the MyForm1 a Module Level Variable and instansiate it in the Form_Load event.

Thank you for the other info and like to MS.  I have raised the points.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:Drifter88zxtW
ID: 7999794
Public Class Form1
    Inherits System.Windows.Forms.Form

    Private aForm2 As Form2 'This is Module Level.

#Region " Windows Form Designer generated code "

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        aForm2 = New Form2()
    End Sub


    Private Sub frmOpenForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles frmOpenForm2.Click
        aForm2.Show() 'If you want Modaly then aForm2.ShowDialog
    End Sub

End Class
0
 
LVL 2

Accepted Solution

by:
Drifter88zxtW earned 200 total points
ID: 7999804
Oooops mistake on example...
That click event is spossed to be a button

Public Class Form1
   Inherits System.Windows.Forms.Form

   Private aForm2 As Form2 'This is Module Level.

#Region " Windows Form Designer generated code "

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       aForm2 = New Form2()
   End Sub


   Private Sub btnOpenForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenForm2.Click
       aForm2.Show() 'If you want Modaly then aForm2.ShowDialog
   End Sub

End Class
0
 
LVL 7

Author Comment

by:EYoung
ID: 8000253
Thank you for taking the extra time to explain that to me.  Although I have several years with vb6, vb.net is quite different and seems more verbose.

I still don't know how to allow the user to click on the "X" in the control box on aForm2 without getting an error like the following after clicking on the button on Form1.


An unhandled exception of type 'System.ObjectDisposedException' occurred in system.windows.forms.dll

Additional information: Cannot access a disposed object named "Form2".


The odd thing is that I get the above error if I call aForm2 using "aForm2.Show" but not if I call using "aForm2.ShowDialog".

Thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question