global data in .net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CsProviders

    global data in .net

    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
  • TJoker .NET [MVP]

    #2
    Re: global data in .net

    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

    *************** *************** **********


    "CsProvider s" <CSProviders@ya hoo.com> wrote in message
    news:018601c381 16$43099170$a10 1280a@phx.gbl.. .[color=blue]
    > 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[/color]


    Comment

    • Armin Zingler

      #3
      Re: global data in .net

      "CsProvider s" <CSProviders@ya hoo.com> schrieb[color=blue]
      > 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?[/color]

      Shared members of classes (AKA fields in Modules) live from their first
      usage til the application's end.
      [color=blue]
      > How do i navigate from one form to another
      > form class? (example me.hide() and form2.show)[/color]

      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

      Comment

      • CSP

        #4
        global data in .net

        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..hi ding all these form
        not going to create any problem in the application, right?
        TIA
        CSP[color=blue]
        >-----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
        >.
        >[/color]

        Comment

        Working...