Re: Navigating Forms
From: Klaus Löffelmann (fornewsgroups_at_loeffelmann.de)
Date: 03/13/04
- Next message: Klaus Löffelmann: "Re: help!"
- Previous message: Herfried K. Wagner [MVP]: "Re: How to Scroll Bottom of RichTextbox into View"
- In reply to: anonymous_at_discussions.microsoft.com: "Re: Navigating Forms"
- Next in thread: Gary: "Re: Navigating Forms - Thanks but another question"
- Reply: Gary: "Re: Navigating Forms - Thanks but another question"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 13 Mar 2004 20:06:25 +0100
In a nutshell:
If you have designed a form, it's not directly usable. Yoe see, in .NET
everything is an object, and that applies for forms, too. Before you can use
any object (that is, as long they are not value types like Integer, String,
DateTime, etc.) you have to instance it, thereby calling its constructor
with *new*.
So lets say you designed a form named frmTest. Before instancing it you have
to define an object varibale, like this:
Dim instanceOfFrmTest as frmTest.
This variable is just a placeholder for a future reference to the actual
form data. It's not instanced yet. To actually instance it, you code:
instaceOfFrmTest = New frmTest.
>From now on you can use the form as often as you want to.
You show it modally with:
instaceOfFrmTest.ShowDialog()
Modal means, that you give the whole program control to the form. The
program logic sort of stops at the ShowDialog, and waits till the form
closes - for example due to some user interaction. Once the forms hides,
closes or disposes itself, the program continues at that position.
If you want to run both instances of the forms simultaneously (one instance
is already running, that would be the main form the program started with),
you call it with
instanceOfFrmTest.Show()
In that case, you don't give away program control at the time exclusively to
the form.
By the way: To shorten things up, you can do the defining and instacing of
an object in one line:
Dim instaceOfFrmTest as New frmTest.
But for every object you use, you do that only once.
About the modifiers: If you define a variable in a procedure (a sub, a
property or a function), the variable is only valid in that procedure. It's
not valid outside. If you want its scope to be in the whole form class, you
define it right after the class definition.
However, I suggest you read about objects and form, provided by the VS-Help.
It'll let you develop programs quicker and more reliable, once you
understood the basic concepts behind it.
Hope this helps,
Klaus
<anonymous@discussions.microsoft.com> schrieb im Newsbeitrag
news:989d01c40926$bb4f2530$a601280a@phx.gbl...
> Klaus,
>
> Can you give me an example? I did try and remove the Dim
> statement from Form2 and Form2 but when I ran the
> program, I got build errors.
>
> On Form2 in a button I entered the following code:
>
> Form1.show
>
> I then got the blue Squiggly line under the code letting
> me know that it's an error. On Form1 I had Dim Form2 as
> new Form2, but it seems that this isn't global through
> the project. Can I Dim the forms in a module? I tried
> this before posting but got an error.
>
> Can you show exact statements of how to do this? Any
> help would be appreciated. Remember, I am just beginning
> the VB .NET and need all the help I can get.
>
> Thanks,
>
> Gary
>
> >-----Original Message-----
> >Gary,
> >
> >An instance of a form is always nothing else but an
> instance of any other
> >object - you only Dim it once! Meaning: If you want to
> use it again, simply
> >show it without Dim.
> >
> >Klaus
> >
> >"Gary" <anonymous@discussions.microsoft.com> schrieb im
> Newsbeitrag
> >news:c59001c4091f$07438c40$a301280a@phx.gbl...
> >> I have a project with three forms. Form1, Form2, and
> >> Form3. On Form1 I have the following:
> >>
> >> Dim Form2 as new Form2
> >> Dim Form3 as new Form3
> >>
> >> Let's say once I get to Form3, I want to return to
> >> Form2. If I put a Form2.Show on a button, and
> Dimension
> >> Form2 as new Form2, I get an error because Form2 has
> >> already been defined on Form1. Is there an easy way to
> >> navigate between forms without using MDI forms? I am a
> >> newbie and was wondering how to do this.
> >>
> >> Thanks,
> >>
> >> Gary
> >>
> >
> >
> >.
> >
- Next message: Klaus Löffelmann: "Re: help!"
- Previous message: Herfried K. Wagner [MVP]: "Re: How to Scroll Bottom of RichTextbox into View"
- In reply to: anonymous_at_discussions.microsoft.com: "Re: Navigating Forms"
- Next in thread: Gary: "Re: Navigating Forms - Thanks but another question"
- Reply: Gary: "Re: Navigating Forms - Thanks but another question"
- Messages sorted by: [ date ] [ thread ]