473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

vb.net loading a form dynamically by name

I have a form that has a left and right panel. In the left panel is a
treeview. The right panel I want to change dynamically based on the
type of node selected. What I'm doing is loading the treeview nodes
through an XML file. As part of each node in the XML, I'm using an
attribute that indicates the name of a sub form to load. As part of
all these little child forms, the main control is a panel, which I
then assign its parent to the right panel of the main form. i.e.
frmSubForm.pnlSub.Parent = pnlBottomRight.

I have the tree loaded fine with no problems. I found some code using
reflection that would load the form as an object, but I haven't
figured out how to assign the panel fields parent because it doesn't
know the "type" of form.

Basically, I'm trying to load sub-forms into a panel on a main form
dynamically given the name of the form in a string.

Hope this makes sense. Is there an easier way to do what I'm trying.

Many thanks,
Mark

Feb 2 '07 #1
5 8537
Mark,

First of all, know that trying a kind of 4th generation tool or let say
something as MS Access gives only disapointments to the one who is building
it. (Or you should be a team of 200 persons). The user wants more
possibilities as Access in all its forms.

If you don't want Midi forms, than maybe can usercontrols do a job for you
instead of forms.

Cor

"marfi95" <ma*****@gmail.comschreef in bericht
news:11**********************@j27g2000cwj.googlegr oups.com...
>I have a form that has a left and right panel. In the left panel is a
treeview. The right panel I want to change dynamically based on the
type of node selected. What I'm doing is loading the treeview nodes
through an XML file. As part of each node in the XML, I'm using an
attribute that indicates the name of a sub form to load. As part of
all these little child forms, the main control is a panel, which I
then assign its parent to the right panel of the main form. i.e.
frmSubForm.pnlSub.Parent = pnlBottomRight.

I have the tree loaded fine with no problems. I found some code using
reflection that would load the form as an object, but I haven't
figured out how to assign the panel fields parent because it doesn't
know the "type" of form.

Basically, I'm trying to load sub-forms into a panel on a main form
dynamically given the name of the form in a string.

Hope this makes sense. Is there an easier way to do what I'm trying.

Many thanks,
Mark

Feb 2 '07 #2
marfi95 wrote:
I have a form that has a left and right panel. In the left panel is a
treeview. The right panel I want to change dynamically based on the
type of node selected.
I've done much the same in an application recently.
What I'm doing is loading the treeview nodes through an XML file.
As part of each node in the XML, I'm using an attribute that
indicates the name of a sub form to load.
OK, with you so far ...
As part of all these little child forms,
Here we part company. Your "editors" want to be UserControls, either
inherited from a base class or implementing an Interface either of which
defines how /every/ editor should behave.
the main control is a panel, which I then assign its parent to the right
panel of the main form.
Hacking Parentage of Controls can be messy, especially across multiple
Forms. UserControls are far easier to work with.
I have the tree loaded fine with no problems. I found some code using
reflection that would load the form as an object,
Object <Variant.

You can't do much [at all] with an Object; you have to get (i.e. cast)
the loaded "Editor" into a Type that your "frame" application knows how
to deal with - either your Base class or Interface.
but I haven't figured out how to assign the panel fields parent
because it doesn't know the "type" of form.
The best you'll get out of the box is a "Forms.Form", which still isn't
particularly useful; you'd have to loop [recursively?] down through the
Controls collection[s] to find the panel you want.

==========
Actually, I took this idea a little further. ;-)

From my file, I load a collection of Objects that
(a) can appear in various arrangements in the TreeView and
(b) can be edited by clicking on one of them (in the Tree).

Each of my my "EditableObjects" exposes a "GetTreeNode" function, which
returns a pre-formatted TreeNode (text, image, etc.) to pop into the
Tree anywhere I need it. This TreeNode has a property that points back
to the /original/ object.
This combination allows me to clear and rearrange the Tree in as many
different groupings as I need.

My "EditableObject" also exposes a "GetEditor" function, that returns a
UserControl (implementing my "IPluginEditor" Interface and) that
contains all the stuff I need to edit that /particular/
"EditableObject". All neatly self-contained.

The only code needed in the "frame" application is for the TreeView to
detect a Treenode from one of my "EditableObjects" (by its Type), get
the object itself (from the Property) and from that get it's "Editor"
and re-Parent that "Editor" into the right-hand panel.

More or less. :-)

HTH,
Phill W.
Feb 2 '07 #3
On Feb 2, 6:54 am, "Phill W." <p-.-a-.-w-a-...@o-p-e-n-.-a-c-.-u-k>
wrote:
marfi95 wrote:
I have aformthat has a left and right panel. In the left panel is a
treeview. The right panel I want to change dynamically based on the
type of node selected.

I've done much the same in an application recently.
What I'm doing is loading the treeview nodes through an XML file.
As part of each node in the XML, I'm using an attribute that
indicates the name of a subformtoload.

OK, with you so far ...
As part of all these little child forms,

Here we part company. Your "editors" want to be UserControls, either
inherited from a base class or implementing an Interface either of which
defines how /every/ editor should behave.
the main control is a panel, which I then assign its parent to the right
panel of the mainform.

Hacking Parentage of Controls can be messy, especially across multiple
Forms. UserControls are far easier to work with.
I have the tree loaded fine with no problems. I found some code using
reflection that wouldloadtheformas an object,

Object <Variant.

You can't do much [at all] with an Object; you have to get (i.e. cast)
the loaded "Editor" into a Type that your "frame" application knows how
to deal with - either your Base class or Interface.
but I haven't figured out how to assign the panel fields parent
because it doesn't know the "type" ofform.

The best you'll get out of the box is a "Forms.Form", which still isn't
particularly useful; you'd have to loop [recursively?] down through the
Controls collection[s] to find the panel you want.

==========
Actually, I took this idea a little further. ;-)

From my file, Iloada collection of Objects that
(a) can appear in various arrangements in the TreeView and
(b) can be edited by clicking on one of them (in the Tree).

Each of my my "EditableObjects" exposes a "GetTreeNode" function, which
returns a pre-formatted TreeNode (text, image, etc.) to pop into the
Tree anywhere I need it. This TreeNode has a property that points back
to the /original/ object.
This combination allows me to clear and rearrange the Tree in as many
different groupings as I need.

My "EditableObject" also exposes a "GetEditor" function, that returns a
UserControl (implementing my "IPluginEditor" Interface and) that
contains all the stuff I need to edit that /particular/
"EditableObject". All neatly self-contained.

The only code needed in the "frame" application is for the TreeView to
detect a Treenode from one of my "EditableObjects" (by its Type), get
the object itself (from the Property) and from that get it's "Editor"
and re-Parent that "Editor" into the right-hand panel.

More or less. :-)

HTH,
Phill W.
Thanks for the input. It sounds like I really need to be going the
direction of usercontrols. The main reason I was using sub forms was
I wanted a clean way of maintaining the UI for each of the sub forms
and not have to mess with hiding these xxx fields when this is
selected, making these visibile when xxx is selected, etc... That
makes for messy maintenance.

Are there any good sites you can point me to for using
usercontrols ? I assume by using usercontrols, I can still do this
dynamically based on the name of the control in a variable ?

Thanks !
Mark

Feb 2 '07 #4
marfi95 wrote:
Thanks for the input. It sounds like I really need to be going the
direction of usercontrols. The main reason I was using sub forms was
I wanted a clean way of maintaining the UI for each of the sub forms
and not have to mess with hiding these xxx fields when this is
selected, making these visibile when xxx is selected, etc... That
makes for messy maintenance.
Agreed!!
You can Design a UserControl in much the same way as you do a Form so,
each one stays neatly self-contained.
Are there any good sites you can point me to for using usercontrols?
'Fraid not - I usually muddle things together as I go along.
I assume by using usercontrols, I can still do this dynamically based
on the name of the control in a variable ?
Probably.
Your best bet might be to have a class that provides the "editors" and
call methods on that to get each one, something like

Class Editors
Public Function Type1Editor() As Type1Editor
Return New Type1Editor
End Function
End Class

....then...

Dim oEditors As New Editors
Dim oEditor As IEditor _
= CallByName( oEditors, "Type1Editor", vbMethod )

HTH,
Phill W.
Feb 5 '07 #5

May be this might help (although several days have gone by). Of course it
needs tweaking since this is only for showing the idea. I did some of the
code while other parts are from one of the MVP's here.

Sub ShowForm(ByVal FormName As String)
Dim ProjectName As String =
Reflection.Assembly.GetExecutingAssembly.GetName.N ame
Try
Dim tyOfStringVariable As Type = Type.GetType(ProjectName & "." &
FormName)
Dim frmObject As Object = Activator.CreateInstance(tyOfStringVariable)

DirectCast(frmObject, Form).StartPosition =
FormStartPosition.CenterParent
DirectCast(frmObject, Form).ShowDialog()
Catch ex As Exception
' TODO
End Try
End Sub

"marfi95" <ma*****@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
>I have a form that has a left and right panel. In the left panel is a
treeview. The right panel I want to change dynamically based on the
type of node selected. What I'm doing is loading the treeview nodes
through an XML file. As part of each node in the XML, I'm using an
attribute that indicates the name of a sub form to load. As part of
all these little child forms, the main control is a panel, which I
then assign its parent to the right panel of the main form. i.e.
frmSubForm.pnlSub.Parent = pnlBottomRight.

I have the tree loaded fine with no problems. I found some code using
reflection that would load the form as an object, but I haven't
figured out how to assign the panel fields parent because it doesn't
know the "type" of form.

Basically, I'm trying to load sub-forms into a panel on a main form
dynamically given the name of the form in a string.

Hope this makes sense. Is there an easier way to do what I'm trying.

Many thanks,
Mark

Feb 8 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Foehammer | last post by:
Hello, I'm trying to load an assembly dynamically using an app domain. This is a proof-of-concept for a larger project, so please excuse the lame class names. TestLib is the dll where all the...
1
by: Benjamin | last post by:
Hi, I'm currently writing a Web Services that interacts with a database. To allow me to use not just one database provider (for example, I could use MS Access, SQL Server or MySQL), the Web...
2
by: Eric | last post by:
I'm trying to dynamically load a user control using on the .NET framework (not Visual Studio). The control was designed in Visual Studio and is named: Disable.ascx The first line is: <%@...
1
by: kanones | last post by:
Hi - I am seeing some performance degradation when I am loading a control dynamically onto a page with multiple other dynamical controls using Page.LoadControl versus dragging and dropping it...
3
by: Holmes | last post by:
Hello Ran into a bit of a problem here and have now exhausted my resources to getting this working What I am trying to do is load and show a simple vb form with a listbox in it Dim...
2
by: nemesis.saurabh | last post by:
hi, Can we dynamically load a user control in the web form. problem i am facing is i have 2 user controls: uc1 and uc2. when my page is loading the functions and variables in the uc1 is...
5
by: news.microsoft.com | last post by:
I'm strongly considering abandoning the one-physical-file-per-page model and going with an arcitecture that simply loads content from classes dynamically. There will be only one page that a user...
2
by: nashtm | last post by:
Hi All I am making the transition to client side programming and am new at JS. I am using YUI's connection manager to dynamically load forms - what I don't know is how to load the accompanying...
1
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
(I've been away from web app programming for a while. Most of my experience has been in 1.1. Now I'm using vb/Dot Net 2.0) Please explain a couple of things. First, I have a simple-minded...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.