473,320 Members | 2,164 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,320 software developers and data experts.

TypeConverter How does it works

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 "DesignerSerializationVisibility " 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

<LocalizableAttribute(True), _
Browsable(True), _
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Visible), _
MergableProperty(False)> _
Public Property MyClassTest() As ClassTest
Get
Return xMyClassTest
End Get
Set(ByVal Value As ClassTest)
xMyClassTest = Value
xMyClassTest_ChangedProperty()
End Set
End Property
please see the code below

<System.ComponentModel.TypeConverter(GetType(Class TypeConverter)), _
EditorBrowsable(EditorBrowsableState.Always), _
Serializable()> _
Public Class ClassTest
Inherits System.MarshalByRefObject
Implements System.IDisposable
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
<EditorBrowsable(EditorBrowsableState.Advanced)> _
Private Function ShouldSerializeColor() As Boolean
Return Not Me.Color.Equals(Color.Red)
End Function
<EditorBrowsable(EditorBrowsableState.Advanced)> _
Private Sub ResetColor()
Me.Color = Color.Red
End Sub
<EditorBrowsable(EditorBrowsableState.Advanced)> _
Private Function ShouldSerializeText() As Boolean
Return Me.Text <> "Texto"
End Function
<EditorBrowsable(EditorBrowsableState.Advanced)> _
Private Sub ResetText()
xText = "Texto"
End Sub

Public Sub Dispose() Implements System.IDisposable.Dispose
xColor = Nothing
End Sub
End Class
' Type Converter Class
Imports System.Reflection
Imports System.ComponentModel
Imports System
Imports System.Drawing
Imports System.Drawing.Design
Imports System.ComponentModel.Design.Serialization
Public Class ClassTypeConverter
Inherits ExpandableObjectConverter
Public Overloads Overrides Function CanConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As
System.Type) As Boolean
Try
If destinationType Is GetType(InstanceDescriptor) Then
Return True
End If
Return MyBase.CanConvertTo(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.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object, ByVal
destinationType As System.Type) As Object
Try
If destinationType Is Nothing Then
Throw New ArgumentNullException("Argumentos Invalidos")
End If
If destinationType Is GetType(InstanceDescriptor) Then
Dim ci As ConstructorInfo =
GetType(ClassTest).GetConstructor(Type.EmptyTypes)
Return New InstanceDescriptor(ci, Nothing, False)
End If
Return MyBase.ConvertTo(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.ComponentModel.ITypeDescriptorContext, ByVal propertyValues As
System.Collections.IDictionary) As Object
Return New ClassTest 'Activator.CreateInstance(GetType(ClassTest))
End Function
Public Overloads Overrides Function GetCreateInstanceSupported(ByVal context
As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function

End Class


Jul 21 '05 #1
0 1204

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

Similar topics

2
by: João Santa Bárbara | last post by:
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...
1
by: Sky Sigal | last post by:
(PS: Cross post from microsoft.pulic.dotnet.framework.aspnet.webcontrols) I've been looking lately for a way to keep the Properties panel for Controls 'clean'... My goal is to keep similar...
5
by: ljlevend | last post by:
Is there a TypeConverter that converts Doubles to percent values in a PropertyGrid? The Windows.Forms.Form.Opacity property seems to use the TypeConverter that I want. Thank you, Lance
0
by: João Santa Bárbara | last post by:
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...
0
by: Alex Clark | last post by:
Hi all, Apologies for the cross-post but I can't determine if this is a VS .NET problem or a VB.NET language issue. I'm using .NET 1.1 SP1, VS 2003 EA, VB.NET. I'm coding a custom component...
0
by: R. Nachtsturm | last post by:
Hi, I would like to create a workable ExpandableObjectConverter for a String Collection (class inheriting from CollectionBase for example and only accepting/returning Strings via...
4
by: swartzbill2000 | last post by:
Hello, I have a TypeConverter for converting between this Enum and Strings. Public Enum DeviceNameEnum dnNone dn2500 dnMirror End Enum 'DeviceNameEnum
11
by: Rolf Welskes | last post by:
Hello, the problem seems to be complex and is in all developments of web-controls which uses own TypeConverter. For this I have here a simple demo-program of the problem: The Control-code: A...
6
by: Larry Smith | last post by:
Hi there, Can anyone provide any insight on why MSFT introduced "TypeConverter.GetProperties()". There are two classes for dealing with metadata in .NET, 'Type" and "TypeDescriptor". Each has a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.