Need help re: vb.net windows forms

  • Thread starter Thread starter jax1148
  • Start date Start date
J

jax1148

In my prject I have three forms:

frmMenu.vb
frmReherse.vb
frmWriteFile.vb

frmMenu.vb is my startup object. How do I call frmReherse.vb from
frmMenu.vb?

Thanks,
Howard
 
Hello!

I think you should simply show the form.

Sub a()
frmReherse.Show()
End Sub
 
There are a few different ways. First, we need to know the class names of
each file. I will assume that your classes are called FrmMenu, FrmReherse,
and so on.

The easiest way to display another form is to use its Show() or ShowDialog()
method from the My.Forms collection.

My.Forms.FrmReherse.ShowDialog()

Or you can use the shortcut for this statement:

FrmReherse.ShowDialog()

ShowDialog() opens the form "modally," which makes it the sole focus of your
application (in general). Using Show() instead opens the form, but allows
the user to switch to other open forms at any time.

A second method is to create a specific instance of the second form, and
open that.

Dim otherForm As FrmReherse
....
otherForm = New FrmReherse
otherForm.ShowDialog()
 
In my prject I have three forms:

frmMenu.vb
frmReherse.vb
frmWriteFile.vb

frmMenu.vb is my startup object. How do I call frmReherse.vb from
frmMenu.vb?

Thanks,
Howard


Dim otherForm As frmReherse
otherForm = New frmReherse
otherForm.ShowDialog()

worked !!!! thanks


FrmReherse.ShowDialog()

got and error message: reference to a non-shared member requires an
object reference
 
If you are building a non-Windows-Forms application, the statement that failed
will certainly fail because My.Forms is not configured. My.Forms only appears
if you create a true Windows application. I assume that you are creating
a DLL or a User Control. In that case, just use the version that worked.
 
Dim otherForm As frmReherse
otherForm = New frmReherse

You could also "one line it" and use

Dim otherForm as New frmReherse()

or even

Dim otherForm as frmReherse = New frmReherse()

It doesn't really matter which you use, it's mainly just personal
preference. I tend to believe it makes the code easier to read if you
just use one line to declare/instatiate a variable.

Thanks,

Seth Rowe
 

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