Creating and showing forms

  • Thread starter Thread starter jy836
  • Start date Start date
J

jy836

I have been working on an application, which to this point has only involved
one Windows Form. I need to create another one; but on the Project menu,
there are two options: "Add Windows Form" and "Add Inherited Form."

I don't know which one to use. Also, once I choose one of those two options,
how can I show the second form when a user clicks a button in the first
form? Thanks in advance.
 
jy836 said:
I have been working on an application, which to this point has only
involved one Windows Form. I need to create another one; but on the
Project menu, there are two options: "Add Windows Form" and "Add
Inherited Form."

I don't know which one to use. Also, once I choose one of those two
options, how can I show the second form when a user clicks a button
in the first form? Thanks in advance.


http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskAddingFormToProject.asp
http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskDisplayingModelessForm.asp

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
jy836 said:
I have been working on an application, which to this point has only involved
one Windows Form. I need to create another one; but on the Project menu,
there are two options: "Add Windows Form" and "Add Inherited Form."

I don't know which one to use. Also, once I choose one of those two options,
how can I show the second form when a user clicks a button in the first
form? Thanks in advance.

Someone else gave you a reference for adding forms / showing them.

As for which option to choose, between "Add Windows Form" and "Add Inherited
Form", well, if I say that all windows forms are classes and the choice is
still not clear, I would highly suggest that you read up and make sure that
you fully understand inheritence and general .NET class fundamentals. I am
afraid that without a firm grasping of these concepts, pruducing effecient
code is nearly impossible.
 
Hi Jy,

In your situation, just add form

And to use it put in your form1 something as
dim frm as form2
frm.showdialog
frm.dispose

I hope this helps,

Cor
 
let your current form be form1 and the newly created form
be form2 which you add as a new form.
in the onclick event of your command button to show this
form add this code:
dim frx as new form2
frx.show
this will show the new form form2 once the button is
clicked !
 
ziad dodin said:
let your current form be form1 and the newly created form
be form2 which you add as a new form.
in the onclick event of your command button to show this
form add this code:
dim frx as new form2
frx.show
this will show the new form form2 once the button is
clicked !

Thanks for all of your responses. With your help, I've gotten the forms up
and running. I'm consistently having problems referencing controls on one
form from another form, though. Is there a simple way to do this? Thanks.
 
Hi,

Something definitely needs to be placed on the .Net box that explains this
:-) Lots of people are missing a basic point which seems to lead them down
the wrong path. Consider that a "form" that you create is a Class. If you
defined any other class with properties and methods you would expect
(normally) to instantiate one, you would refer to the properties using dot
notation, you'd recognize that you couldn't see any private members of the
class unless you had public accessors.

It isn't different for classes inheriting from System.Windows.Forms

Does this help?
 
Tom Leylan said:
Hi,

Something definitely needs to be placed on the .Net box that explains this
:-) Lots of people are missing a basic point which seems to lead them down
the wrong path. Consider that a "form" that you create is a Class. If you
defined any other class with properties and methods you would expect
(normally) to instantiate one, you would refer to the properties using dot
notation, you'd recognize that you couldn't see any private members of the
class unless you had public accessors.

It isn't different for classes inheriting from System.Windows.Forms

Does this help?

Thanks for your reply. Maybe I should explain what it is I'm trying to do.
:-) I have a form titled MainForm (the one that is automatically placed in
any VB Windows Application project, but I renamed it), and another new one
called PrefsForm (a form used for setting user preferences). I created the
new form (PrefsForm) by selecting "Add Windows Form" from the Project menu.

When I click on a menu in MainForm, this is the code that is executed:

Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem8.Click
Dim Prefs As New PrefsForm
Prefs.ShowDialog()
End Sub

What I want to do is when the user types a path and filename of a database
into a text box on PrefsForm, the ConnectionString of OleDbConnection1
(which is on MainForm) will be changed accordingly. But I can't seem to find
a way to access the OleDbConnection1 control on MainForm from PrefsForm.
Hope this makes sense...thanks for your help!
 
jy836 said:
Thanks for your reply. Maybe I should explain what it is I'm trying to do.

Generally speaking explanations usually do help :-) In this case the answer
is... "you don't want to do it that way." Problem solved :-)

Seriously if you "really wanted" to have your PrefsForm interact with
controls on your main form you could pass along a reference to the main
form... again consider what you would do if these weren't forms but were any
other object which you happened to be working with. This could be done in
the constructor of PrefsForm for instance. You could also set it up to just
the control along. But neither case is ideal.

Rather when your main form receives control again have it get the
information out of PrefsForm. After the ShowDialog you can add code that
access it. Note that you still have a reference at that time. The form
can't be seen but it exists.

As a third alternative you can create a single public class that
encapsulates all the user preference information and both your main form and
the PresForm can reference it. Doing it that way would mean you wouldn't
have to come up with some scheme to pass along all the current user
preferences if they select the PrefsForm again.

Tom
 
Back
Top