Solved

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

Posted on 2012-04-09
4
170 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
[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
4 Comments
 
LVL 36

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 36

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

Industry Leaders: 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

627 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