I found it
I used the typeconverter class to convert the property value to string, and used it again to restore the value.
I used the following code to get it:
Dim tc As TypeConverter = TypeDescriptor.GetConverter(myProperty.PropertyType)
If tc.CanConvertFrom(GetType(String)) Then
Try
Dim val As Object = tc.ConvertFrom(PropertyValue)
myProperty.SetValue(C, val)
Catch ex As Exception
Debug.Print("Setting " + PropStr + " failed:" + ex.Message)
End Try
regards,
Ahmed Hashish
Thanks
I need to ask another question.
I can now create the controls, How I could set the control properties? I have all control properties in a string format I'm trying to do it like this:
Private Sub SetProperty(ByVal C As Control, ByVal PropertyName As String, ByVal PropertyValue As String)
Dim Props As PropertyDescriptorCollection = TypeDescriptor.GetProperties(C)
Dim myProperty As PropertyDescriptor = Props.Find(PropertyName, True)
If Not myProperty Is Nothing Then myProperty.SetValue(C, PropertyValue) 'I got error "Object of type 'System.String' cannot be converted to type 'System.Windows.Forms.AnchorStyles'
End Sub
The PropertyName is the output of the method "myProperty.GetValue(C).ToString"
Regards,
Ahmed Hashish
Herfried K. Wagner said:
I'm trying to create a new control and add it to a form at runtime.
The function should be like this:
private void AddControl(Form f, string ControlType, string ConrtolName)
Take a look at this code snippet:
<URL:
http://dotnet.mvps.org/dotnet/code/techniques/#ClassByName>