Hi all
i have a class that i have made and i made an Typeconverter as well, and my
problem is
the code genereated in my form is
Dim ClassTest1 As TestApplication .ClassTest = New TestApplication .ClassTest
Me.MyClassTest = ClassTest1
Wich is quite good, but my problem is in my property browser i cannot change
any of my properties
' need the "DesignerSerial izationVisibili ty " this in visible because this
is a form that must be inherited and i don´t want this property tobe writen
in the child form. unless it was changed in the child form .
i have declare my property like this
<LocalizableAtt ribute(True), _
Browsable(True) , _
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Visible), _
MergablePropert y(False)> _
Public Property MyClassTest() As ClassTest
Get
Return xMyClassTest
End Get
Set(ByVal Value As ClassTest)
xMyClassTest = Value
xMyClassTest_Ch angedProperty()
End Set
End Property
please see the code below
<System.Compone ntModel.TypeCon verter(GetType( ClassTypeConver ter)), _
EditorBrowsable (EditorBrowsabl eState.Always), _
Serializable()> _
Public Class ClassTest
Inherits System.MarshalB yRefObject
Implements System.IDisposa ble
Private xText As String = "Texto"
Private xColor As System.Drawing. Color = Color.Red
Public Event ChangedProperty ()
Event testesss As EventHandler
Public Property Text() As String
Get
Return xText
End Get
Set(ByVal Value As String)
xText = Value
RaiseEvent ChangedProperty ()
End Set
End Property
Public Property Color() As System.Drawing. Color
Get
Return xColor
End Get
Set(ByVal Value As System.Drawing. Color)
xColor = Value
RaiseEvent ChangedProperty ()
End Set
End Property
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Function ShouldSerialize Color() As Boolean
Return Not Me.Color.Equals (Color.Red)
End Function
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Sub ResetColor()
Me.Color = Color.Red
End Sub
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Function ShouldSerialize Text() As Boolean
Return Me.Text <> "Texto"
End Function
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Sub ResetText()
xText = "Texto"
End Sub
Public Sub Dispose() Implements System.IDisposa ble.Dispose
xColor = Nothing
End Sub
End Class
' Type Converter Class
Imports System.Reflecti on
Imports System.Componen tModel
Imports System
Imports System.Drawing
Imports System.Drawing. Design
Imports System.Componen tModel.Design.S erialization
Public Class ClassTypeConver ter
Inherits ExpandableObjec tConverter
Public Overloads Overrides Function CanConvertTo(By Val context As
System.Componen tModel.ITypeDes criptorContext, ByVal destinationType As
System.Type) As Boolean
Try
If destinationType Is GetType(Instanc eDescriptor) Then
Return True
End If
Return MyBase.CanConve rtTo(context, destinationType )
Catch ex As Exception
MessageBox.Show ("Erro CanConvertTo " & ex.StackTrace)
End Try
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Try
If destinationType Is Nothing Then
Throw New ArgumentNullExc eption("Argumen tos Invalidos")
End If
If destinationType Is GetType(Instanc eDescriptor) Then
Dim ci As ConstructorInfo =
GetType(ClassTe st).GetConstruc tor(Type.EmptyT ypes)
Return New InstanceDescrip tor(ci, Nothing, False)
End If
Return MyBase.ConvertT o(context, culture, value, destinationType )
Catch ex As Exception
MessageBox.Show ("Erro ConvertTo" & ex.StackTrace)
End Try
End Function
Public Overloads Overrides Function CreateInstance( ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal propertyValues As
System.Collecti ons.IDictionary ) As Object
Return New ClassTest 'Activator.Crea teInstance(GetT ype(ClassTest))
End Function
Public Overloads Overrides Function GetCreateInstan ceSupported(ByV al context
As System.Componen tModel.ITypeDes criptorContext) As Boolean
Return True
End Function
End Class
i have a class that i have made and i made an Typeconverter as well, and my
problem is
the code genereated in my form is
Dim ClassTest1 As TestApplication .ClassTest = New TestApplication .ClassTest
Me.MyClassTest = ClassTest1
Wich is quite good, but my problem is in my property browser i cannot change
any of my properties
' need the "DesignerSerial izationVisibili ty " this in visible because this
is a form that must be inherited and i don´t want this property tobe writen
in the child form. unless it was changed in the child form .
i have declare my property like this
<LocalizableAtt ribute(True), _
Browsable(True) , _
DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Visible), _
MergablePropert y(False)> _
Public Property MyClassTest() As ClassTest
Get
Return xMyClassTest
End Get
Set(ByVal Value As ClassTest)
xMyClassTest = Value
xMyClassTest_Ch angedProperty()
End Set
End Property
please see the code below
<System.Compone ntModel.TypeCon verter(GetType( ClassTypeConver ter)), _
EditorBrowsable (EditorBrowsabl eState.Always), _
Serializable()> _
Public Class ClassTest
Inherits System.MarshalB yRefObject
Implements System.IDisposa ble
Private xText As String = "Texto"
Private xColor As System.Drawing. Color = Color.Red
Public Event ChangedProperty ()
Event testesss As EventHandler
Public Property Text() As String
Get
Return xText
End Get
Set(ByVal Value As String)
xText = Value
RaiseEvent ChangedProperty ()
End Set
End Property
Public Property Color() As System.Drawing. Color
Get
Return xColor
End Get
Set(ByVal Value As System.Drawing. Color)
xColor = Value
RaiseEvent ChangedProperty ()
End Set
End Property
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Function ShouldSerialize Color() As Boolean
Return Not Me.Color.Equals (Color.Red)
End Function
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Sub ResetColor()
Me.Color = Color.Red
End Sub
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Function ShouldSerialize Text() As Boolean
Return Me.Text <> "Texto"
End Function
<EditorBrowsabl e(EditorBrowsab leState.Advance d)> _
Private Sub ResetText()
xText = "Texto"
End Sub
Public Sub Dispose() Implements System.IDisposa ble.Dispose
xColor = Nothing
End Sub
End Class
' Type Converter Class
Imports System.Reflecti on
Imports System.Componen tModel
Imports System
Imports System.Drawing
Imports System.Drawing. Design
Imports System.Componen tModel.Design.S erialization
Public Class ClassTypeConver ter
Inherits ExpandableObjec tConverter
Public Overloads Overrides Function CanConvertTo(By Val context As
System.Componen tModel.ITypeDes criptorContext, ByVal destinationType As
System.Type) As Boolean
Try
If destinationType Is GetType(Instanc eDescriptor) Then
Return True
End If
Return MyBase.CanConve rtTo(context, destinationType )
Catch ex As Exception
MessageBox.Show ("Erro CanConvertTo " & ex.StackTrace)
End Try
End Function
Public Overloads Overrides Function ConvertTo(ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal culture As
System.Globaliz ation.CultureIn fo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Try
If destinationType Is Nothing Then
Throw New ArgumentNullExc eption("Argumen tos Invalidos")
End If
If destinationType Is GetType(Instanc eDescriptor) Then
Dim ci As ConstructorInfo =
GetType(ClassTe st).GetConstruc tor(Type.EmptyT ypes)
Return New InstanceDescrip tor(ci, Nothing, False)
End If
Return MyBase.ConvertT o(context, culture, value, destinationType )
Catch ex As Exception
MessageBox.Show ("Erro ConvertTo" & ex.StackTrace)
End Try
End Function
Public Overloads Overrides Function CreateInstance( ByVal context As
System.Componen tModel.ITypeDes criptorContext, ByVal propertyValues As
System.Collecti ons.IDictionary ) As Object
Return New ClassTest 'Activator.Crea teInstance(GetT ype(ClassTest))
End Function
Public Overloads Overrides Function GetCreateInstan ceSupported(ByV al context
As System.Componen tModel.ITypeDes criptorContext) As Boolean
Return True
End Function
End Class
Comment