Link to home
Start Free TrialLog in
Avatar of Peter Allen
Peter AllenFlag for United States of America

asked on

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

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.
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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
Avatar of Peter Allen

ASKER

mas_oz2003,

Unfortunately this was not quite clear givem my code above.  Can you elaborate please?
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()
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial