Solved

Using an ArrayList to Hold Form References

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

Independent Software Vendors: 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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

740 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