Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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 …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

19 Experts available now in Live!

Get 1:1 Help Now