Solved

Access Public Properties of a Form created dynamically in VB.NET

Posted on 2012-04-09
4
166 Views
Last Modified: 2012-04-16
Experts,

I was successful in createing the UI that I wanted for a form I am working on.  The UI has a ToolStrip with the buttons for the various pages.  To keep things simple lets say FormOne, Form2, Form3, etc.

As I select the desired button in the ToolStrip the appropriate Form is loaded in a Form Panel.  Here is how the form shows in the Panel:

        Dim f_PanelForm As Form = clsMod_CreateObjects.CreateForm(p_sWindowPanelFormName)
        p_sWindowPanelFormVisible = "Show"
        f_PanelForm.TopLevel = False
        f_PanelForm.Parent = Me
        Panel_Form.Controls.Add(f_PanelForm)
        f_PanelForm.Show()

What I also have are some Public Properties on theform I just loaded and displayed.  How would I reference these Public Properties.  I've hear of using the Form's modifier, but I am not quite sure how to do this when my variable f_PanelForm holds the reference.

Thank you in advance for the assistance.
0
Comment
Question by:Peter Allen
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 37825636
You need to cast PanelForm  to your class type using CType or DirectCast and then access the required properties
http://www.codeproject.com/Articles/5044/Cheat-Sheet-Casting-in-VB-NET-and-C
0
 

Author Comment

by:Peter Allen
ID: 37829042
mas_oz2003,

Unfortunately this was not quite clear givem my code above.  Can you elaborate please?
0
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 37830376
Can you tell me what the form name is?
e.g. Given the form below
Public Class Form1
Public ReadOnly Property MyTextBox() As TextBox
    Get
        Return textBox1
    End Get
End Property

'Assumption: Dynamic forms are created as:
 Dim f_PanelForm As Form = clsMod_CreateObjects.CreateForm("Form1")
' Cast to Form1
Dim cast_Form As Form = CType(f_PanelForm , Form1)
'  then you can call prop
' cast_Form.MyTextBox()
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 150 total points
ID: 37833041
You can access the properties on the form even if it does not appear in intellisense. This is late binding. But make sure that property would exist at runtime or use try...catch block.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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