473,385 Members | 1,317 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,385 software developers and data experts.

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.
Oct 12 '06 #1
2 2004

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.

Oct 12 '06 #2
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.Dra wing2D.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(DesignerSerializa tionVisibility.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(DesignerSerializa tionVisibility.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(DesignerSerializa tionVisibility.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(DesignerSerializa tionVisibility.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(DesignerSerializa tionVisibility.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(DesignerSerializa tionVisibility.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(DesignerSerializa tionVisibility.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.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.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.

Oct 15 '06 #3

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

Similar topics

2
by: Shanthi | last post by:
I am using property grid in C# application. Property grid displays the propeties properly. But I have some problem in displaying custom validation message. I have integer type property. When I...
0
by: Andreas Poller | last post by:
Hi, I want to customize a Property Grid in the following way: The Property Grid should show a property which value should be changed by a dropdown-listbox. For example, there is a property...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
3
by: Nice Chap | last post by:
Is it possible to have custom property pages for a Component and if so how I can write one please ? Also, is it possible to reuse the drop down box that we get for Data Source and Data Member...
3
by: Steve Teeples | last post by:
I was wondering if there is a way to force a property within a property grid to update and then display a modified value when when a second property (true/false) is toggled? -- Steve
1
by: John Kraft | last post by:
Hi all, I'm trying to use a property grid, and what I'm trying to do seems to really elude me. I've been using the property grid for a short period of time, and this is the first thing I...
2
by: Ray Cassick | last post by:
I am looking for a way to hide a property I created on a user control from a property grid at runtime but allow it to be seen at design time. Any ideas? I tried setting the category of the...
0
by: Hans Koller | last post by:
Hello group, I design a class to bind it to a property grid for easy modification of some settings. My problem is now that I want to raise an event when a settings has been changed. Thats not a...
1
by: asharda | last post by:
I have a custom property grid. I am using custom property grid as I do not want the error messages that the propertygrid shows when abphabets are entered in interger fields. The custom property...
10
by: Derek Hart | last post by:
I can set focus to my property grid by using propgrid.Focus - but how can I set the default property that is always first? Or just set focus to the default property? Can this be done?
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

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.