I have an xml with control definitions
<?xml version="1.0" encoding="utf-8"?>
<Controls>
<TabControl>
<Properties>
<Dock>5</Dock>
</Properties>
<TabPage>
<TextBox>
<Properties>
<Text>Id:</Text>
<Location>106,12</Location>
<Size>113,20</Size>
<BorderStyle>2</BorderStyle>
</Properties>
</TextBox>
<MyControl>
<Properties>
<Visible>True</Visible>
<Location>106,33</Location>
<Size>113,20</Size>
<Enabled>True</Enabled>
<BorderStyle>2</BorderStyle>
<Text>Action:</Text>
<TabIndex>0</TabIndex>
</Properties>
</MyControl>
<Properties>
<Text>Details</Text>
</Properties>
</TabPage>
</TabControl>
</Controls>
Ok. As you can see I have in this example One tabControl , with one TabPage. The TabPage has one TextBox and one MyControl.
I am able to read the xml and add all the controls except the MyControl.
The reason is that I cannot find the type.
Explain:
in order to run through the xml and add the controls I wan tot find what type it is. So I use this line of code:
Dim oType As Type = FindType("System.Windows.Forms." & elem.Name.ToString)
FindType is a function I found here: Best way to get a Type object from a string in .NET
Unfortunately I cannot figure out what to add in this function to find MyControl.
MyControl is just a custom control added to my solution.
I know that I can use an if inside the FindType function
if base is Nothing then
if name.Contains("MyControl")Then
base = GetType(MyControl)
End If
End If
If base IsNot Nothing Then Return base
My problem is that I have 3 custom Controls and maybe in the future I will add more.
Is any way to have something generic?
Another question is that in FindType function I have to use “System.Windows.Forms.” for the name.
and I discovered that without it the function doesn’t return anything.
I am thinking that this is happened because I call that function when I am building the form , so not everything is loaded yet?
Thanks for your time
if
FindType("System.Windows.Forms." & elem.Name.ToString)doesn’t find anything, just tryFindType(elem.Name.ToString)it looks like the code for FindType in the question you linked should find it if you just pass only the name, since it looks at all the types in the executing assembly.