Solved

Using an ArrayList to Hold Form References

Posted on 2013-05-15
2
187 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

776 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