473,724 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2028

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.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

<za***@construc tion-imaging.comwrot e in message
news:11******** *************@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.

Oct 15 '06 #3

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

Similar topics

2
9254
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 give invalid values for the property it is throwing System exception as follows. "Invalid Property Value. Is not a valid value for Int32. Though I have custom validation message in the Property set system throws exception before this.
0
1121
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 called "animal" and when I want to change the value of the property in the property grid it should show me a dropdown-box with standard values like "cow","cat" or "bird".
0
5568
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 is used to view the state of the running jobs and schedule new jobs. The control also runs in the context of Internet Explorer (we do this so the administrators of the jobs can always receive the latest control). The property grid is used to...
3
1791
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 inside VS.net's property grid, for my component ? If so any pointers would be immensely appreciated. Thank you.
3
11293
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
6478
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 haven't been able to do. I have some products... like t-shirts... and these products have particular property / value pairs. I'd like the property grid to look like this:
2
2689
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 property to 'Design' and that does not do it. I tried adding the 'DesignOnly' attribute and that does not do it.
0
1511
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 problem with some "normal" properties (see property DisplayGrid). But when I use a subclass and TypeConverter the setter of the property is not called. Set(ByVal value As LineSetting) m_Limit1 = value
1
4382
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 grid doesn't show colloections i.e. if I have a List<Objectthen the Collection is shown but when I click on the "..." button next to it nothing comes up. If I say CustomPropertyGrid p = new CustomPropertyGrid(); p.SelectedObject = new...
10
10039
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
8868
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8741
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9389
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6689
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4771
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2149
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.