13 Replies - 3567 Views - Last Post: 29 July 2012 - 06:05 AM Rate Topic: ***** 1 Votes

#1 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 135
  • Joined: 19-May 12

Adding Properties to the Group

Posted 28 July 2012 - 01:27 AM

I Know how to Create Properties in a Class

I create properties like

    Property GotFocusBackColor() As Color
        Get
            Return TGotFocusBack
        End Get
        Set(ByVal value As Color)
            TGotFocusBack = value
        End Set
    End Property

    Property GotFocusForeColor() As Color
        Get
            Return TGotFocusText
        End Get
        Set(ByVal value As Color)
            TGotFocusText = value
        End Set
    End Property



Now I want to Add them to a group

For Example :
Font is a Group
and FontName, FontSize, etc... are its properties

I mean I want to show them like font Group in PropertyGrid of a textbox

and one more problem:
1) Suppose I have a Boolean Property viz. ChangeColors
2) If ChangeColors = True Then
Show Other two Properties viz. BackColor & Forecolor
Else
Hide Other two properties viz. BackColor & Forecolor
End If
I want to implement this in code but dont know how???????????

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Adding Properties to the Group

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 956
  • View blog
  • Posts: 3,676
  • Joined: 02-July 08

Re: Adding Properties to the Group

Posted 28 July 2012 - 07:22 AM

You need to add some attributes to the properties and possible Import System.ComponentModel. If you use a category name that does not exist a new one is created. Many attributes can be added to a property - separate with a comma.

<Category("Font"), Description(""), Browsable(True)>
Public Property....

This post has been edited by _HAWK_: 28 July 2012 - 07:23 AM

Was This Post Helpful? 1
  • +
  • -

#3 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 135
  • Joined: 19-May 12

Re: Adding Properties to the Group

Posted 28 July 2012 - 02:28 PM

I have used the attributes as you told But I cant see any Changes in the PropertyGrid

This is what I have Tried
<Category("FocusColor"), DescriptionAttribute("FocusColor"), Browsable(True)> _
    Public Property MouseOverBackColor() As Color
        Get
            Return MOverBack
        End Get
        Set(ByVal value As Color)
            MOverBack = value
        End Set
    End Property


Thanks for Replying
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 956
  • View blog
  • Posts: 3,676
  • Joined: 02-July 08

Re: Adding Properties to the Group

Posted 28 July 2012 - 02:46 PM

You have to rebuild the solution after making the changes and poss delete and re-add the control.
Was This Post Helpful? 1
  • +
  • -

#5 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 135
  • Joined: 19-May 12

Re: Adding Properties to the Group

Posted 28 July 2012 - 03:14 PM

Ya, Now I get some changes but thats not what i wanted

I get it in the categorized view but I dont want that
I want to show these properties in a group in alphabetical view
Was This Post Helpful? 0
  • +
  • -

#6 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 135
  • Joined: 19-May 12

Re: Adding Properties to the Group

Posted 28 July 2012 - 05:09 PM

I mean I want Expandable Property

For More Information Please See the attached Image
Attached Image

By using Your Code I got is described in the Image Below
Attached Image
Was This Post Helpful? 0
  • +
  • -

#7 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 956
  • View blog
  • Posts: 3,676
  • Joined: 02-July 08

Re: Adding Properties to the Group

Posted 28 July 2012 - 05:21 PM

It has been awhile since I played with that stuff. I see what I can find.
Was This Post Helpful? 0
  • +
  • -

#8 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 135
  • Joined: 19-May 12

Re: Adding Properties to the Group

Posted 28 July 2012 - 05:28 PM

Thanks man I will wait for your reply
Was This Post Helpful? 0
  • +
  • -

#9 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 956
  • View blog
  • Posts: 3,676
  • Joined: 02-July 08

Re: Adding Properties to the Group

Posted 28 July 2012 - 08:23 PM

It has a lot to do with the UITypeEditor. Wish I had more time to help - your assignment is to research, test and evaluate. It's something you need to be proficient at to be a programmer anyway.
Was This Post Helpful? 0
  • +
  • -

#10 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 135
  • Joined: 19-May 12

Re: Adding Properties to the Group

Posted 28 July 2012 - 08:50 PM

Yup! I will give it a try for sure
Thanks for the reply
Was This Post Helpful? 0
  • +
  • -

#11 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 956
  • View blog
  • Posts: 3,676
  • Joined: 02-July 08

Re: Adding Properties to the Group

Posted 28 July 2012 - 08:58 PM

Similar case.
Was This Post Helpful? 1
  • +
  • -

#12 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 135
  • Joined: 19-May 12

Re: Adding Properties to the Group

Posted 28 July 2012 - 10:56 PM

I think This helps me
I will Try and say you the results
The three Links by the other guy on Page:2 are Helpful
And 2nd link from that three links is awesome
Was This Post Helpful? 0
  • +
  • -

#13 Vishal1419  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 135
  • Joined: 19-May 12

Re: Adding Properties to the Group

Posted 29 July 2012 - 02:47 AM

Yup! that helped me after trying some Combinations

Thanks HAWK You are really a good programmer

Here is my Code

Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Globalization
Imports System.Windows.Forms

Public Class MyTxtBox
    Inherits TextBox

    Private Focus_Color As New FocusColorAppearance
    Private components As System.ComponentModel.IContainer = Nothing


    Public Sub New()
        InitializeComponent()

    End Sub

    Protected Overrides Sub Dispose(ByVal disposing As Boolean)

        If disposing AndAlso (components IsNot Nothing) Then
            components.Dispose()
        End If

        MyBase.Dispose(disposing)

    End Sub

    <Browsable(True), _
    EditorBrowsable(EditorBrowsableState.Always), _
    Category("Custom Properties"), _
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public Property FocusColors() As FocusColorAppearance

        Get
            Return Me.Focus_Color
        End Get

        Set(ByVal value As FocusColorAppearance)
            Me.Focus_Color = value
        End Set

    End Property

    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
        'Me.autoscalemode = System.Windows.Forms.AutoScaleMode.Font

    End Sub

    'These 2 Events are Declared for GotFocus and LostFocus of TextBox BackColor and ForeColor
    Private Sub MyTxtBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
        Me.BackColor = FocusColorAppearance.GotFocus_BackColor
        Me.ForeColor = FocusColorAppearance.GotFocus_Forecolor

    End Sub

    Private Sub MyTxtBox_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LostFocus
        Me.BackColor = FocusColorAppearance.LostFocus_BackColor
        Me.ForeColor = FocusColorAppearance.LostFocus_ForeColor
    End Sub

End Class

<TypeConverter(GetType(FocusColorConverterClass))> _
Public Class FocusColorAppearance

    Public Shared GotFocus_BackColor As Color
    Public Shared LostFocus_BackColor As Color
    Public Shared GotFocus_Forecolor As Color
    Public Shared LostFocus_ForeColor As Color

    <Browsable(True), NotifyParentProperty(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(GetType(Color), "")> _
    Public Property GotFocusBackColor() As Color
        Get
            Return GotFocus_BackColor
        End Get
        Set(ByVal value As Color)
            GotFocus_BackColor = value
        End Set
    End Property

    <Browsable(True), NotifyParentProperty(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(GetType(Color), "")> _
    Public Property LostFocusBackColor() As Color
        Get
            Return LostFocus_BackColor
        End Get
        Set(ByVal value As Color)
            LostFocus_BackColor = value
        End Set
    End Property

    <Browsable(True), NotifyParentProperty(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(GetType(Color), "")> _
    Public Property GotFocusForeColor() As Color
        Get
            Return GotFocus_Forecolor
        End Get
        Set(ByVal value As Color)
            GotFocus_Forecolor = value
        End Set
    End Property

    <Browsable(True), NotifyParentProperty(True), EditorBrowsable(EditorBrowsableState.Always), DefaultValue(GetType(Color), "")> _
    Public Property LostFocusForeColor() As Color
        Get
            Return LostFocus_ForeColor
        End Get
        Set(ByVal value As Color)
            LostFocus_ForeColor = value
        End Set
    End Property

End Class

Public Class FocusColorConverterClass
    Inherits ExpandableObjectConverter

    ' This override prevents the PropertyGrid from 
    ' displaying the full type name in the value cell.
    Public Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object

        If destinationType Is GetType(String) Then
            'Return ""
            Dim FC As FocusColorAppearance = CType(value, FocusColorAppearance)
            Dim s As String
            s = "GB : " & FC.GotFocusBackColor.ToString & ", GF : " & FC.GotFocusForeColor.ToString & ", LB : " & FC.LostFocusBackColor.ToString & ", LF : " & FC.LostFocusForeColor.ToString
            s = s.Replace("Color [", "")
            s = s.Replace("]", "")
            Return s
            'Return "GotFocusBackColor : " & FC.GotFocusBackColor.ToString & ", GotFocusForeColor : " & FC.GotFocusForeColor.ToString & ", LostFocusBackColor : " & FC.LostFocusBackColor.ToString & "LostFocusForeColor : " & FC.LostFocusForeColor.ToString
        End If

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

    End Function
End Class


Was This Post Helpful? 1
  • +
  • -

#14 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 956
  • View blog
  • Posts: 3,676
  • Joined: 02-July 08

Re: Adding Properties to the Group

Posted 29 July 2012 - 06:05 AM

Glad you got it - nice work. Thanks for sharing the solution.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1