By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,525 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

global data in .net

P: n/a
i am a newbie to .net programming, i am having problem
with global data and form instanciation. My questions are
How do i maintain global data in windows forms
applications? How do i navigate from one form to another
form class? (example me.hide() and form2.show)
TIA
CSP
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In VB6, you were able to refer to any form by the form-name (like Form1,
frmMain, etc) and you were also able to create multiple instances of any
form like:
Dim frm as New Form2

In VB.NET you cannot code against the form-name (the class) anymore. You
always have to create an instance of any form before using it. The new
problem here is that you cannot get a hold on any of the application's forms
(instances) unless you have a public variable referencing that form for you
to use (global data as you said).
One way of doing that is adding a Module to your app and declaring variables
to hold references to the form instances that you'll need across your app:

Module YourModule
Public mainForm as frmMain
Public clockForm as frmClock

End Module

In your code, when you open the main form for the first time, you store the
reference in the appropriate variable:

mainForm = New frmMain()
mainForm.Show()

Then you can use the variable mainForm anywhere else in your app to
manipulate the main form.

That's the idea.

HTH
--
TJoker, MCSD.NET
MVP: Paint, Notepad, Solitaire

****************************************
"CsProviders" <CS*********@yahoo.com> wrote in message
news:01****************************@phx.gbl...
i am a newbie to .net programming, i am having problem
with global data and form instanciation. My questions are
How do i maintain global data in windows forms
applications? How do i navigate from one form to another
form class? (example me.hide() and form2.show)
TIA
CSP

Nov 20 '05 #2

P: n/a
"CsProviders" <CS*********@yahoo.com> schrieb
i am a newbie to .net programming, i am having problem
with global data and form instanciation. My questions are
How do i maintain global data in windows forms
applications?
Shared members of classes (AKA fields in Modules) live from their first
usage til the application's end.
How do i navigate from one form to another
form class? (example me.hide() and form2.show)


Write your own Sub Main:

Sub Main
Dim F as Form1
f.Show
Application.Run
End Sub

In Form1:
Dim f2 as Form2
f2 = New Form2

Me.Hide
f2.Show

--
Armin

Nov 20 '05 #3

P: n/a
CSP
Actually i did try both solutios, but unable to hide the
form1. And i got into a problem of showing two form at the
same time. So i used visible property of form1 as false to
get rid of its visibility. I think i m missing something
here...anyways i have another question. If i have nearly
40 to 50 forms in an application..hiding all these form
not going to create any problem in the application, right?
TIA
CSP
-----Original Message-----
i am a newbie to .net programming, i am having problem
with global data and form instanciation. My questions are
How do i maintain global data in windows forms
applications? How do i navigate from one form to another
form class? (example me.hide() and form2.show)
TIA
CSP
.

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.