Solved

Using an ArrayList to Hold Form References

Posted on 2013-05-15
2
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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