Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Declaring a class in start form, use it in another.
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00674416
Message ID:
00674552
Vues:
18
One approach you could use is by declaring public variables in a modulate and use that to start up your application instead of the form. Here is some sample code:
Module MainModule
    Public form_start As MyMainForm
    Public oForm1 As Form1
    Public oForm2 As Form2

    Sub main()
        Dim context As New ApplicationContext()
        form_start = New MyMainForm()
        context.MainForm = form_start
        System.Windows.Forms.Application.Run(context)
    End Sub
End Module
You will need to go into your project's properties and change the Startup object to be "Sub Main" in this sample. Once this is done, then you can reference the variables form_start, oForm1, and oForm2 from anywhere in your app. In your form_start form, just set the variables equal to the newly instantiated form like:
oForm1 = New Form1()
In your instanse of Form2 you can reference Form1 like:
Messagebox(oForm1.TextBox1.Text)
Another approach to take is to use a Forms collection object that you store references to instantiated forms. You will need to manually maintain this collection. This approach is used if you need to have multiple instances of the same form class.

>Being a VFP programmer I can do it in Fox so there must be a way in VB.net. I have defined a class and load it in my start form. My start form calls several other forms. How do I instanciate my class so that it is accessible to all forms?
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform