Home All Groups Group Topic Archive Search About
Author
12 Oct 2006 7:25 PM
Lespaul36
I have a control that I have made that uses a custom class for storage of
some of the information.  I want it to display in the VS.Net 2003 property
grid in the IDE like the Font property does, so a use can expand it and set
the properties.  How do I do this?  Thanks in advance.

Author
12 Oct 2006 8:00 PM
zacks
Lespaul36 wrote:
> I have a control that I have made that uses a custom class for storage of
> some of the information.  I want it to display in the VS.Net 2003 property
> grid in the IDE like the Font property does, so a use can expand it and set
> the properties.  How do I do this?  Thanks in advance.

I think you can do that by dragging the control into the VS Toolbox.
Author
15 Oct 2006 4:18 AM
Lespaul36
I figured out how to do it.  I had to make a type converter  to do it.  I
will post the code so that others who look at this can figured.

Here is the TypeConverter:


Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports System.ComponentModel.Design.Serialization
Imports System.Text

Public Class GradientTypeConverter
    Inherits ExpandableObjectConverter

   Public Overloads Overrides Function CanConvertTo(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As
System.Type) As Boolean
        If destinationType Is GetType(Gradient) Then
            Return True
        End If
        MyBase.CanConvertFrom(context, destinationType)
    End Function

    Public Overloads Overrides Function CanConvertFrom(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As
System.Type) As Boolean
        If sourceType Is GetType(String) Then
            Return True
        End If

        Return MyBase.CanConvertFrom(context, sourceType)
    End Function

    Public Overloads Overrides Function ConvertFrom(ByVal context As
System.ComponentModel.ITypeDescriptorContext, ByVal culture As
System.Globalization.CultureInfo, ByVal value As Object) As Object
        If TypeOf value Is String Then
            Try
                Dim s As String = CType(value, String)
                Dim tempProp As String()
                Dim _Gradient As New Gradient
                If s.Length > 0 Then
                    tempProp = Split(s, ";")
                    If Not IsNothing(tempProp) AndAlso tempProp.Length > 0
Then
                        Dim i As Short
                        Dim tempValues() As String
                        For i = 0 To CShort(tempProp.Length - 1)
                            tempValues = Split(tempProp(i), "=")
                            tempValues(0) = LCase(Trim(tempValues(0)))
                            If IsNothing(tempValues(1)) Then tempValues(1) =
""
                            Select Case tempValues(0)
                                Case "bar color 1"
                                    _Gradient.BarColor1 =
Color.FromArgb(CInt(tempValues(1)))
                                Case "bar color 2"
                                    _Gradient.BarColor2 =
Color.FromArgb(CInt(tempValues(1)))
                                Case "gradient mode"
                                    _Gradient.GradientMode =
CType(System.Enum.Parse(GetType(System.Drawing.Drawing2D.LinearGradientMode)
, (tempValues(1))), LinearGradientMode)
                                Case "sigma focus"
                                    _Gradient.SigmaFocus =
CInt(tempValues(1))
                                Case "sigma scale"
                                    _Gradient.SigmaScale =
CInt(tempValues(1))
                                Case "use sigmabell"
                                    _Gradient.UseSigmaBell =
CBool(tempValues(1))
                            End Select
                        Next
                    End If
                End If
            Catch ex As Exception
                ' if we got this far, complain that we
                ' couldn't parse the string
                '
                Throw New ArgumentException("Can not convert '" &
value.ToString & "' to type Person")
            End Try
        End If
        Return MyBase.ConvertFrom(context, culture, value)

    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
        If (destinationType Is GetType(System.String) AndAlso TypeOf value
Is Gradient) Then
            Dim _Gradient As Gradient = CType(value, Gradient)
            Dim _GradientBuilder As New StringBuilder
            With _GradientBuilder
                .Append("Bar Color 1=" & _Gradient.BarColor1.ToArgb.ToString
& ";")
                .Append("Bar Color 2=" & _Gradient.BarColor2.ToArgb.ToString
& ";")
                .Append("Gradient Mode=" & _Gradient.GradientMode & ";")
                .Append("Sigma Focus=" & _Gradient.SigmaFocus & ";")
                .Append("Sigma Scale=" & _Gradient.SigmaScale & ";")
                .Append("Use SigmaBell=" & _Gradient.UseSigmaBell & ";")
            End With
            Return _GradientBuilder.ToString
        End If

        Return MyBase.ConvertTo(context, culture, value, destinationType)

    End Function
End Class



Here is the class that I am converting:

Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Imports System.ComponentModel.Design.Serialization

''' ------------------------------------------------------------------------
-----
''' <summary>
''' Stores information for making a gradient style ProgressBar.
''' </summary>
''' <remarks>
''' Stores information for making a gradient style ProgressBar.
''' </remarks>
''' <history>
'''  [David] 10/10/2006 Created
''' </history>
''' ------------------------------------------------------------------------
-----
<Serializable(), ComVisible(True),
TypeConverter(GetType(GradientTypeConverter))> _
Public Class Gradient
    Implements IDisposable

    Private mCol1 As Color = Color.FromKnownColor(KnownColor.ActiveCaption)
    Private mCol2 As Color = Color.Red
    Private mGradientStyle As LinearGradientMode =
LinearGradientMode.Horizontal
    Private mblnIsSigmaBell As Boolean = False
    Private msngSigmaScale As Single = 0.75
    Private msngSigmaFocus As Single = 0.5
    Private mintSigmaLocation As Integer = 50
    Private mintSigmaScale As Integer = 75





''' ------------------------------------------------------------------------
-----
    ''' <summary>
    ''' Creates a new Gradient Class.
    ''' </summary>
    ''' <remarks>
    ''' Creates a new Gradient Class.
    ''' </remarks>
    ''' <history>
    '''  [David] 10/10/2006 Created
    ''' </history>




''' ------------------------------------------------------------------------
-----
    Public Sub New()
        'do nothing
    End Sub





''' ------------------------------------------------------------------------
-----
    ''' <summary>
    ''' Creates a new Gradient Class.
    ''' </summary>
    ''' <param name="BarColor1">
    ''' Sets the color of the first bar of the ProgressBar.
    ''' </param>
    ''' <param name="BarColor2">
    ''' Sets the color of the second bar of the ProgressBar.
    ''' </param>
    ''' <param name="GradientStyle">
    ''' Sets the gradient style of the ProgressBar.
    ''' </param>
    ''' <remarks>
    ''' </remarks>
    ''' <history>
    '''  [David] 10/10/2006 Created
    ''' </history>




''' ------------------------------------------------------------------------
-----
    Public Sub New(ByVal BarColor1 As Color, ByVal BarColor2 As Color, ByVal
GradientStyle As LinearGradientMode)
        mCol1 = BarColor1
        mCol2 = BarColor2
        mGradientStyle = GradientStyle
    End Sub





''' ------------------------------------------------------------------------
-----
    ''' <summary>
    ''' The mode of the gradient draw.
    ''' </summary>
    ''' <value>
    ''' The style of the drawing brush as LinearGradientMode
    ''' </value>
    ''' <remarks>
    ''' The mode of the gradient draw.
    ''' </remarks>
    ''' <history>
    '''  [David] 10/10/2006 Created
    ''' </history>




''' ------------------------------------------------------------------------
-----

<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
Browsable(True), Description("The mode of the gradient draw."),
Category("Appeance"), DefaultValue("")> _
        Public Property GradientMode() As LinearGradientMode
        Get
            Return mGradientStyle
        End Get
        Set(ByVal Value As LinearGradientMode)
            mGradientStyle = Value
        End Set
    End Property





''' ------------------------------------------------------------------------
-----
    ''' <summary>
    ''' The color of the first bar in the ProgressBar.
    ''' </summary>
    ''' <value>
    ''' A color that represents the first color in the ProgresBar.
    ''' </value>
    ''' <remarks>
    ''' The color of the first bar in the ProgressBar.
    ''' </remarks>
    ''' <history>
    '''  [David] 10/10/2006 Created
    ''' </history>




''' ------------------------------------------------------------------------
-----

<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
Category("Appeance"), Browsable(True), Description("The color of the first
bar in the ProgressBar.")> _
        Public Property BarColor1() As Color
        Get
            Return mCol1
        End Get
        Set(ByVal Value As Color)
            mCol1 = Value
        End Set
    End Property





''' ------------------------------------------------------------------------
-----
    ''' <summary>
    ''' The color of the second bar in the ProgressBar.
    ''' </summary>
    ''' <value>
    ''' A color that represents the second color in the ProgresBar.
    ''' </value>
    ''' <remarks>
    ''' The color of the second bar in the ProgressBar.
    ''' </remarks>
    ''' <history>
    '''  [David] 10/10/2006 Created
    ''' </history>




''' ------------------------------------------------------------------------
-----

<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
Category("Appeance"), Browsable(True), Description("The color of the second
bar in the ProgressBar.")> _
        Public Property BarColor2() As Color
        Get
            Return mCol2
        End Get
        Set(ByVal Value As Color)
            mCol2 = Value
        End Set
    End Property





''' ------------------------------------------------------------------------
-----
    ''' <summary>
    ''' Decides if the ProgressBar will use SigmaBella.  Default is False.
    ''' </summary>
    ''' <remarks>
    ''' Decides if the ProgressBar will use SigmaBella.  Default is False.
    ''' </remarks>
    ''' <history>
    '''  [David] 10/12/2006 Created
    ''' </history>




''' ------------------------------------------------------------------------
-----

<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
Category("Appeance"), Browsable(True), Description("Decides if the
ProgressBar will use SigmaBella.  Default is False.")> _
    Public Property UseSigmaBell() As Boolean
        Get
            Return Me.mblnIsSigmaBell
        End Get
        Set(ByVal Value As Boolean)
            Me.mblnIsSigmaBell = Value
        End Set
    End Property





''' ------------------------------------------------------------------------
-----
    ''' <summary>
    ''' An integer between 0 and 100 that sets the size of the SigmaBell.
Default is 75.
    ''' </summary>
    ''' <value>
    ''' Creates a gradient falloff based on a bell-shaped curve.
    ''' </value>
    ''' <remarks>
    ''' An integer between 0 and 100 that sets the size of the SigmaBell.
Default is 75.
    ''' </remarks>
    ''' <history>
    '''  [David] 10/12/2006 Created
    ''' </history>




''' ------------------------------------------------------------------------
-----

<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
Category("Appeance"), Browsable(True), Description("An integer between 0 and
100 that sets the size of the SigmaBell.  Default is 75.")> _
            Public Property SigmaFocus() As Integer
        Get
            Return Me.mintSigmaLocation
        End Get
        Set(ByVal Value As Integer)
            If Value < 0 Or Value > 100 Then
                Throw New ArgumentException("Value " & Value & " is ouside
of the value of 0-100")
            Else
                mintSigmaLocation = Value
                msngSigmaFocus = CSng(Value / 100.0F)
            End If
        End Set
    End Property


<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
Category("Appeance"), Browsable(True), Description("An integer between 0 and
100 that sets the size of the SigmaBell.  Default is 75.")> _
    Public Property SigmaScale() As Integer
        Get
            Return Me.mintSigmaScale
        End Get
        Set(ByVal Value As Integer)
            If Value < 0 Or Value > 100 Then
                Throw New ArgumentException("Value " & Value & " is ouside
of the value of 0-100")
            Else
                mintSigmaScale = Value
                msngSigmaScale = CSng(Value / 100.0F)
            End If
        End Set
    End Property


    Friend Function GetSigmaFocus() As Single
        Return msngSigmaFocus
    End Function

    Friend Function GetSigmaScale() As Single
        Return Me.msngSigmaScale
    End Function

#Region "  Dispose"
    Public Sub Dispose() Implements System.IDisposable.Dispose
        Me.mCol1 = Nothing
        Me.mCol2 = Nothing
    End Sub

#End Region

End Class

Here is the property in the control that I am working on:

''' ------------------------------------------------------------------------
-----
    ''' <summary>
    ''' Sets the properties for a Gradient ProgressBar.
    ''' </summary>
    ''' <remarks>
    ''' Sets the properties for a Gradient ProgressBar. Only works for solid
ProgressBar.
    ''' </remarks>
    ''' <history>
    '''  [David] 10/10/2006 Created
    ''' </history>




''' ------------------------------------------------------------------------
-----

<DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Category("Appearance"), Description("Sets the properties for a Gradient
ProgressBar."), Browsable(True)> _
        Public ReadOnly Property GradientInfo() As Gradient
        Get
            Return Me.mGradient
        End Get
    End Property

<za***@construction-imaging.com> wrote in message
Show quoteHide quote
news:1160683237.904383.84720@h48g2000cwc.googlegroups.com...
>
> Lespaul36 wrote:
> > I have a control that I have made that uses a custom class for storage
of
> > some of the information.  I want it to display in the VS.Net 2003
property
> > grid in the IDE like the Font property does, so a use can expand it and
set
> > the properties.  How do I do this?  Thanks in advance.
>
> I think you can do that by dragging the control into the VS Toolbox.
>