|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I read the thread about how to call another form just by name, but im having problems implementing that into my own solution.
I have a separate User Control library, but the main project has something like an option dialog. Im building the options through an XML tree, thus a treeview. What im trying to do is have the user click on a node in the tree, and the user control associated with it will be created and displayed on the screen. The issue is that im making room so if we want to add different controls to the page without having to recompile the software, like a plug-in thingie. Any suggestions?? BTW, i keep getting nothing back when i run a step debug through the ObjectFinder function: Imports System.Windows Imports System.Windows.Forms Imports System.Reflection Public Class ObjectFinder Public Shared Function CreateObjectInstance(ByVal objectName As String) As Object Dim obj As Object Try If objectName.LastIndexOf(".") = -1 Then 'Appends the root namespace if not specified. objectName = [Assembly].GetEntryAssembly.GetName.Name & "." & objectName End If obj = [Assembly].GetEntryAssembly.CreateInstance(objectName) Catch ex As Exception obj = Nothing End Try Return obj End Function Public Shared Function CreateForm(ByVal formName As String) As Form ' Return the instance of the form by specifying its name. Return DirectCast(CreateObjectInstance(formName), Form) End Function ' I added this one Public Shared Function CreateControl(ByVal controlName As String) As UserControl Return DirectCast(CreateObjectInstance(controlName), UserControl) End Function End Class |
|
#2
|
|||
|
|||
|
Found the cause
I found out what the error is. It seems that when im using the GetEntryAssembly, im getting the Assembly from the executing program. However, when i use GetExecutingAssembly, I get it from the code where the function exists, mainly the dll that i am using.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > .NET Development > Calling User Controls by name |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|