Property Grid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lespaul36

    #1

    Property Grid

    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.


  • zacks@construction-imaging.com

    #2
    Re: Property Grid


    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.

    Comment

    • Lespaul36

      #3
      Re: Property Grid

      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.Componen tModel
      Imports System.Runtime. InteropServices
      Imports System.Componen tModel.Design.S erialization
      Imports System.Text

      Public Class GradientTypeCon verter
      Inherits ExpandableObjec tConverter

      Public Overloads Overrides Function CanConvertTo(By Val context As
      System.Componen tModel.ITypeDes criptorContext, ByVal destinationType As
      System.Type) As Boolean
      If destinationType Is GetType(Gradien t) Then
      Return True
      End If
      MyBase.CanConve rtFrom(context, destinationType )
      End Function

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

      Return MyBase.CanConve rtFrom(context, sourceType)
      End Function

      Public Overloads Overrides Function ConvertFrom(ByV al context As
      System.Componen tModel.ITypeDes criptorContext, ByVal culture As
      System.Globaliz ation.CultureIn fo, 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(tempP rop) 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(temp Values(0)))
      If IsNothing(tempV alues(1)) Then tempValues(1) =
      ""
      Select Case tempValues(0)
      Case "bar color 1"
      _Gradient.BarCo lor1 =
      Color.FromArgb( CInt(tempValues (1)))
      Case "bar color 2"
      _Gradient.BarCo lor2 =
      Color.FromArgb( CInt(tempValues (1)))
      Case "gradient mode"
      _Gradient.Gradi entMode =
      CType(System.En um.Parse(GetTyp e(System.Drawin g.Drawing2D.Lin earGradientMode )
      , (tempValues(1)) ), LinearGradientM ode)
      Case "sigma focus"
      _Gradient.Sigma Focus =
      CInt(tempValues (1))
      Case "sigma scale"
      _Gradient.Sigma Scale =
      CInt(tempValues (1))
      Case "use sigmabell"
      _Gradient.UseSi gmaBell =
      CBool(tempValue s(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 ArgumentExcepti on("Can not convert '" &
      value.ToString & "' to type Person")
      End Try
      End If
      Return MyBase.ConvertF rom(context, culture, value)

      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
      If (destinationTyp e Is GetType(System. String) AndAlso TypeOf value
      Is Gradient) Then
      Dim _Gradient As Gradient = CType(value, Gradient)
      Dim _GradientBuilde r As New StringBuilder
      With _GradientBuilde r
      .Append("Bar Color 1=" & _Gradient.BarCo lor1.ToArgb.ToS tring
      & ";")
      .Append("Bar Color 2=" & _Gradient.BarCo lor2.ToArgb.ToS tring
      & ";")
      .Append("Gradie nt Mode=" & _Gradient.Gradi entMode & ";")
      .Append("Sigma Focus=" & _Gradient.Sigma Focus & ";")
      .Append("Sigma Scale=" & _Gradient.Sigma Scale & ";")
      .Append("Use SigmaBell=" & _Gradient.UseSi gmaBell & ";")
      End With
      Return _GradientBuilde r.ToString
      End If

      Return MyBase.ConvertT o(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.Componen tModel
      Imports System.Runtime. InteropServices
      Imports System.Componen tModel.Design.S erialization

      ''' ------------------------------------------------------------------------
      -----
      ''' <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(G etType(Gradient TypeConverter)) _
      Public Class Gradient
      Implements IDisposable

      Private mCol1 As Color = Color.FromKnown Color(KnownColo r.ActiveCaption )
      Private mCol2 As Color = Color.Red
      Private mGradientStyle As LinearGradientM ode =
      LinearGradientM ode.Horizontal
      Private mblnIsSigmaBell As Boolean = False
      Private msngSigmaScale As Single = 0.75
      Private msngSigmaFocus As Single = 0.5
      Private mintSigmaLocati on 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="GradientS tyle">
      ''' 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 LinearGradientM ode)
      mCol1 = BarColor1
      mCol2 = BarColor2
      mGradientStyle = GradientStyle
      End Sub





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




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

      <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Visible),
      Browsable(True) , Description("Th e mode of the gradient draw."),
      Category("Appea nce"), DefaultValue("" )_
      Public Property GradientMode() As LinearGradientM ode
      Get
      Return mGradientStyle
      End Get
      Set(ByVal Value As LinearGradientM ode)
      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>




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

      <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Visible),
      Category("Appea nce"), Browsable(True) , Description("Th e 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>




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

      <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Visible),
      Category("Appea nce"), Browsable(True) , Description("Th e 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>




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

      <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Visible),
      Category("Appea nce"), Browsable(True) , Description("De cides if the
      ProgressBar will use SigmaBella. Default is False.")_
      Public Property UseSigmaBell() As Boolean
      Get
      Return Me.mblnIsSigmaB ell
      End Get
      Set(ByVal Value As Boolean)
      Me.mblnIsSigmaB ell = 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>




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

      <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Visible),
      Category("Appea nce"), 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.mintSigmaLoc ation
      End Get
      Set(ByVal Value As Integer)
      If Value < 0 Or Value 100 Then
      Throw New ArgumentExcepti on("Value " & Value & " is ouside
      of the value of 0-100")
      Else
      mintSigmaLocati on = Value
      msngSigmaFocus = CSng(Value / 100.0F)
      End If
      End Set
      End Property


      <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Visible),
      Category("Appea nce"), 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.mintSigmaSca le
      End Get
      Set(ByVal Value As Integer)
      If Value < 0 Or Value 100 Then
      Throw New ArgumentExcepti on("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.msngSigmaSca le
      End Function

      #Region " Dispose"
      Public Sub Dispose() Implements System.IDisposa ble.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>




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

      <DesignerSerial izationVisibili ty(DesignerSeri alizationVisibi lity.Content),
      Category("Appea rance"), Description("Se ts the properties for a Gradient
      ProgressBar."), Browsable(True) _
      Public ReadOnly Property GradientInfo() As Gradient
      Get
      Return Me.mGradient
      End Get
      End Property

      <zacks@construc tion-imaging.comwrot e in message
      news:1160683237 .904383.84720@h 48g2000cwc.goog legroups.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.
      >

      Comment

      Working...