Form.Show problem

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

In VB6 I have this in frmMain:

Private sub Button1_Click()
frmSecondOne.Show
me.Hide
End Sub

and then in frmSecondOne:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
frmMain.Show
End Sub

How do I do this in VB.NET?
 
How about this? Using ShowDialog to find out when the form is closed.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim newForm As New frmSecondOne

Me.Hide()
newForm.ShowDialog()
Me.Show()
End Sub
 
No good. I need to show other forms while showing the second form.
Also, how would I reference a textbox or Listbox on frmMain?

VB6:

Text1 = frmMain.Text1
 
Kevin said:
In VB6 I have this in frmMain:

Private sub Button1_Click()
frmSecondOne.Show
me.Hide
End Sub

and then in frmSecondOne:

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
frmMain.Show
End Sub

How do I do this in VB.NET?

\\\
Public Sub Main()
Dim f As New Form1()
f.Show()
Application.Run()
End Sub
///

In a button:

\\\
Dim f2 As New Form2()
f2.Show()
Me.Close()
///

You can exit the application by calling 'Application.ExitThread'.
 
In this case you will need to add a module to your application and add the
line:
Public frmMe As Form

On the first form add an onload event like:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
frmMe = Me
End Sub

For your button add the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim newForm As New frmSecondOne

Me.Hide()
newForm.Show()
End Sub

Then on the closing event on frmSecondOne:
Private Sub frmSecondOne_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
frmMe.Show()
End Sub

You will be able to reference the first form from anywhere by using:
frmMe.Text1.Text = "Hello World"

Regards
Scott.
 
Works fine except for referencing the first form. I have a listbox on
the first form I'm trying to reference. I get the error "Listbox1 is
not a member of 'System.Windows.Forms.Form'". What am I doing wrong?
 
Just started with .net from vb6 I tried the code Cant Ref Form1 If .net is
totally opp there has to be an easy way to reference the hidden Object
(Form)
 
I just posted A ? About recalling A hidden Object(Form1) I think Kevin's ?
is the same After Hiding Form1 we want to Show or unhide the same Instance
of the form. Thats what Kevins code would do in vb6.
 
Kevin I have you answer. This code make Form1 and Form2 work just like in
VB6

I new there had to be a simple way to only have one instance of every form
in your app and be able to effect the form and controls exactly like in vb6.
So I Finally figured out an easy way to do it.

Module Module1

Public WithEvents frm1 As New Form1()

Public WithEvents frm2 As New Form2()

Public jim As String

Public Sub main()

Application.Run(frm1)

End Sub

End Module

____________________________________________________________________________
_________

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

frm2.Show()

Me.Hide()

End Sub

_________________"Code in
Form1_______________________________________________________________________
_______

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

frm1.Visible = True

End Sub

________________"Code in
Forn2_______________________________________________________________________
_____________
 
Didnt have to use the WithEvents key word
Jim Burns said:
Kevin I have you answer. This code make Form1 and Form2 work just like in
VB6

I new there had to be a simple way to only have one instance of every form
in your app and be able to effect the form and controls exactly like in vb6.
So I Finally figured out an easy way to do it.

Module Module1

Public WithEvents frm1 As New Form1()

Public WithEvents frm2 As New Form2()

Public jim As String

Public Sub main()

Application.Run(frm1)

End Sub

End Module

____________________________________________________________________________
_________

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

frm2.Show()

Me.Hide()

End Sub

_________________"Code in
Form1_______________________________________________________________________
_______

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

frm1.Visible = True

End Sub

________________"Code in
Forn2_______________________________________________________________________
_____________
 
You Dont need the "withevents" key word and I dont know how the jim as
string got there but dont need that as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top