Solved

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

Posted on 2012-04-09
4
167 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Regex validation 2 25
SQL LINE CONTINUATION ISSUE 12 33
VB net, code to modify xlsx file, and errors when it is ran on NON-developer PC... 2 26
write xml in vb.net 2 24
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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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 …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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