Solved

Using an ArrayList to Hold Form References

Posted on 2013-05-15
2
185 Views
Last Modified: 2013-06-05
Experts,

For a project I have several tables that I want to provide access to for the user.  I would like to have each form load in a Panel on the main form.  I was thinking of using an ArrayList do do this wth the following dimensions:

14 x 3 = 14 Forms by three Properties

The properties would be:

Form Reference
Form Name as String
Form Visible as Boolean

I thought using an ArrayList would be the best way to do this, but would this eat up resources to quickly?

If not an ArrayList what would you suggest?

Thanks!
0
Comment
Question by:Peter Allen
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 150 total points
ID: 39169403
No, this would not "eat" up too much resources.  It's a drop in the bucket...

I recommend you create a Class to hold those values:
    Public Class FormData
        Public Reference As Form
        Public Name As String
        Public Visible As Boolean
    End Class

Open in new window


Then use a List(Of FormData) to hold those values:
Public Class Form1

    Public Class FormData
        Public Reference As Form
        Public Name As String
        Public Visible As Boolean
    End Class

    Private OpenedForms As New List(Of FormData)

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim frm As New Form
        frm.Text = "Hello"
        frm.Show()

        Dim fd As New FormData
        fd.Reference = frm
        fd.Name = frm.Text
        fd.Visible = True
        OpenedForms.Add(fd)
    End Sub

End Class

Open in new window

0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 100 total points
ID: 39170229
As any object based on a class instead of a structure, a Form is a reference object. That means that when you pass a form from one place to another, you are not passing a copy with all the properties in it, you are simply passing the reference, a pointer, the address where the form is in memory.

Simply add your forms to the array list, and all you will have in memory, other than the relatively small overhead needed for the few properties of the ArrayList itself (such as Count), will be 14 pointers (14 x 4 bytes or 14 x 8 bytes depending on whether you are running in 32-bits or 64-bits). And you will not be limited to the 3 properties, but to all the propeties of the forms.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now