Page 1 of 2 12 LastLast
Results 1 to 40 of 47

Thread: Expandable Props [RESOLVED]

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Resolved Expandable Props [RESOLVED]

    Basically, (in my user control) I have a child class with properties and these will be expandable (like the Size property).
    Now on the UC I have a second set of props which expose these props. would both sets of props need an ExpandableObjectConverter
    or would the dummy UC props pass everything needed to the underlying class of expandable props?

    Thanks


    Edit: You can skip to post #36 since that is where the new part starts.
    Last edited by RobDog888; Apr 6th, 2005 at 06:50 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Expandable Properties

    You should only need to define the TypeConverter Once.

    For example if you added a property of the type System.Drawing.Point to your user control (this is the same type as the Size Property). You dont need to do anything else because the TypeConverter was already made by M$ (System.Drawing.PointConverter)

    --

    Once a TypeConverter is defined you dont need to explicitly tell Visual Studio to use it.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    Thanks, but would I pass a class from the dummy props defined in the UC to the converter or pass my
    child class - gradientpanel? Also, these props are custom and not any default ones.

    Ex.
    DrawStyles
    - GraphicsMode
    - BrushType
    - Color1
    - Color2
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Expandable Properties

    So somewhere in your Control you got

    VB Code:
    1. Public Class DrawStylesConverter
    2.       Inherits TypeConverter
    3.       '.....

    and you got your DrawStyles Class

    VB Code:
    1. 'This attribute links the TypeConverter to the DrawStyles type,
    2. 'After this is defined, the propertygrid will automatically use the
    3. 'Custom TypeConverter
    4. <TypeConverter(GetType(DrawStylesConverter))>
    5. Public Class DrawStyles
    6.    'ect


    ----

    VB Code:
    1. Public Class MyPanel
    2.    ' ect...
    3.    
    4.    Private _MyDrawingStyles as DrawStyles
    5.  
    6.    Public Property DrawingStyles() as DrawStyles
    7.        Get
    8.           Return _MyDrawingStyles
    9.        End Get
    10.        Set(Value as DrawStyles)
    11.            m_MyDrawStyles
    12.        End Set
    13.    End Property

    VB Code:
    1. Public Class MyUserControl
    2.    'ect
    3.  
    4.    Public Property DrawingStyles() as DrawStyles
    5.        Get
    6.           Return MyPanelControlInstance.DrawingStyles
    7.        End Get
    8.        Set(Value as DrawStyles)
    9.            MyPanelControlInstance.DrawingStyles = Value
    10.        End Set
    11.    End Property


    should to the trick
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  5. #5

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    Thanks, thats what I was hoping to hear. I'm working on it right now to see if I can get it going.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    Ok, almost finished it but a question arises. My expandable properties have to be concatinated
    in the DrawStyles property text field?

    DrawStyles = Vertical; LinearGradient; Color.White; Color.Blue;

    I wanted something generic in there but not sure what to put or how to keep
    it readonly without making the entire property read only.

    DrawStyles = ?
    - DrawMode = Vertical
    - BrushType = LinearGradient
    - Color1 = Color.White
    - Color2 = Color.Blue

    etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    I have everything in place but no expansion

    My prop tree -

    DrawStyles = LineraGradient; Color.White; Color.Blue
    - DrawMode = LinearGradient
    - Color1 = Color.White
    - Color2 = Color.Blue

    I am Inheriting in my class the ExpandableObjectConverter and added the attribute for TypeConverter.


    VB Code:
    1. <TypeConverter(GetType(GraphicsModeConverter))> _
    2. Friend Class GradientPanel
    3.  
    4.     Public Property Blah, Blah, ...
    5.  
    6. End Class
    7.  
    8. Friend Class GraphicsModeConverter
    9.  
    10.     Inherits ExpandableObjectConverter
    11. '...
    12. '...
    Last edited by RobDog888; Mar 17th, 2005 at 06:00 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Expandable Properties

    Here's an example of what I think you're trying to do, maybe you missed a step:

    DrawStylesConverter:
    VB Code:
    1. Imports System.ComponentModel
    2. Imports System.Globalization
    3.  
    4. ' Expandable TypeConverter for the DrawStyles class
    5. Public Class DrawStylesConverter
    6.    Inherits ExpandableObjectConverter
    7.  
    8.    Private m_lastValue As DrawStyles = New DrawStyles
    9.  
    10.    Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal t As Type) As Boolean
    11.       ' Indicate which types this class can convert "From"
    12.       If t Is GetType(String) Then
    13.          Return True
    14.       End If
    15.       Return MyBase.CanConvertFrom(context, t)
    16.    End Function
    17.  
    18.    Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
    19.       If value.GetType() Is GetType(String) Then
    20.          Try
    21.             ' Attempt to parse the string representation
    22.             ' into the constituent properties
    23.             Dim ds As New DrawStyles
    24.             Dim s As String = value
    25.             Dim c As String
    26.  
    27.             Dim props As String() = s.Split(",".ToCharArray())
    28.  
    29.             ds.DrawMode = [Enum].Parse(GetType(DrawMode), Trim(props(0)))
    30.             c = Trim(props(1))
    31.             If Not IsNumeric(c) Then
    32.                ds.Color1 = Color.FromKnownColor([Enum].Parse(GetType(KnownColor), c))
    33.             Else
    34.                ds.Color1 = Color.FromArgb(Convert.ToInt32(c))
    35.             End If
    36.             c = Trim(props(2))
    37.             If Not IsNumeric(c) Then
    38.                ds.Color2 = Color.FromKnownColor([Enum].Parse(GetType(KnownColor), c))
    39.             Else
    40.                ds.Color2 = Color.FromArgb(Convert.ToInt32(c))
    41.             End If
    42.  
    43.             Return ds
    44.  
    45.          Catch ex As Exception
    46.             ' Revert back to the last good value if an error is encountered
    47.             ' trying to parse the entered "text" value for the constiuent properties
    48.             Return m_lastValue
    49.  
    50.          End Try
    51.       End If
    52.       MyBase.ConvertFrom(context, culture, value)
    53.    End Function
    54.  
    55.    Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal t As Type) As Boolean
    56.       ' Indicate which types this class can convert "To"
    57.       If t Is GetType(DrawStyles) Then Return True
    58.       Return MyBase.CanConvertTo(context, t)
    59.    End Function
    60.  
    61.    Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destType As Type) As Object
    62.       If destType Is GetType(String) Then
    63.          ' Attempt to convert the value into a string representation
    64.          Try
    65.             Dim styles As DrawStyles = CType(value, DrawStyles)
    66.             m_lastValue = styles
    67.             Return String.Format("{0}, {1}, {2}", styles.DrawMode, styles.Color1.Name, styles.Color2.Name)
    68.  
    69.          Catch ex As Exception
    70.             ' If there was an error, display it instead of the string value
    71.             Return String.Format("Error: {0}", ex.Message)
    72.  
    73.          End Try
    74.       End If
    75.       Return MyBase.ConvertTo(context, culture, value, destType)
    76.    End Function
    77. End Class
    DrawStyles:
    VB Code:
    1. Imports System.ComponentModel
    2.  
    3. '
    4. ' Draw Styles Class: Demonstates an expandable property
    5. '
    6. <TypeConverter(GetType(DrawStylesConverter))> _
    7. Public Class DrawStyles
    8.    Private _drawMode As DrawMode = DrawMode.Normal
    9.    Private _color1 As Color = Color.Red
    10.    Private _color2 As Color = Color.Blue
    11.  
    12.    ' Specify property defaults and indicate that the property grid should repait when
    13.    ' this property value changes (to make sure the string representation is updated)
    14.    <DefaultValue(GetType(DrawMode), "Normal"), RefreshProperties(RefreshProperties.Repaint)> _
    15.    Public Property DrawMode() As DrawMode
    16.       Get
    17.          Return _drawMode
    18.       End Get
    19.       Set(ByVal Value As DrawMode)
    20.          _drawMode = Value
    21.       End Set
    22.    End Property
    23.  
    24.    <DefaultValue(GetType(Color), "Red"), RefreshProperties(RefreshProperties.Repaint)> _
    25.    Public Property Color1() As Color
    26.       Get
    27.          Return _color1
    28.       End Get
    29.       Set(ByVal Value As Color)
    30.          _color1 = Value
    31.       End Set
    32.    End Property
    33.  
    34.    <DefaultValue(GetType(Color), "Blue"), RefreshProperties(RefreshProperties.Repaint)> _
    35.    Public Property Color2() As Color
    36.       Get
    37.          Return _color2
    38.       End Get
    39.       Set(ByVal Value As Color)
    40.          _color2 = Value
    41.       End Set
    42.    End Property
    43. End Class
    MyControl:
    VB Code:
    1. Imports System.ComponentModel
    2.  
    3. '
    4. ' Example control implementing a custom expandable property
    5. '
    6. Public Class MyControl
    7.    Inherits System.Windows.Forms.UserControl
    8.  
    9. #Region " Windows Form Designer generated code "
    10.  
    11.    Public Sub New()
    12.       MyBase.New()
    13.  
    14.       'This call is required by the Windows Form Designer.
    15.       InitializeComponent()
    16.  
    17.       'Add any initialization after the InitializeComponent() call
    18.  
    19.    End Sub
    20.  
    21.    'UserControl overrides dispose to clean up the component list.
    22.    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    23.       If disposing Then
    24.          If Not (components Is Nothing) Then
    25.             components.Dispose()
    26.          End If
    27.       End If
    28.       MyBase.Dispose(disposing)
    29.    End Sub
    30.  
    31.    'Required by the Windows Form Designer
    32.    Private components As System.ComponentModel.IContainer
    33.  
    34.    'NOTE: The following procedure is required by the Windows Form Designer
    35.    'It can be modified using the Windows Form Designer.  
    36.    'Do not modify it using the code editor.
    37.    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    38.       components = New System.ComponentModel.Container
    39.    End Sub
    40.  
    41. #End Region
    42.  
    43.    Private _drawStyle As New DrawStyles
    44.  
    45.    ' Indicate this property should appear in the property grid and that
    46.    ' Code should be generate for the child properties of this property and
    47.    ' not the property itself.
    48.    <Browsable(True), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    49.    Public Property DrawStyle() As DrawStyles
    50.       Get
    51.          Return _drawStyle
    52.       End Get
    53.       Set(ByVal Value As DrawStyles)
    54.          _drawStyle = Value
    55.       End Set
    56.    End Property
    57.  
    58.    ' Implement separate "ShouldSerialize" and "Reset" methods because of the
    59.    ' Complex nature of the expandable property type
    60.    Private Function ShouldSerializeDrawStyle() As Boolean
    61.       ' Return True to indicate the value is not default and should be persisted
    62.       Return Not (_drawStyle.DrawMode = DrawMode.Normal AndAlso _drawStyle.Color1.Equals(Color.Red) AndAlso _drawStyle.Color2.Equals(Color.Blue))
    63.    End Function
    64.  
    65.    Private Sub ResetDrawStyle()
    66.       ' Reset the property to a default value
    67.       _drawStyle = New DrawStyles
    68.    End Sub
    69. End Class

  9. #9

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    I think you got what I was trying to do exactly. I had all three properties on the control and in the child class.
    Then I had the child class' converting the props to make them expandable.

    Your demo looks great! Give me a few minutes to incorporate it into my uc for testing.

    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    I am getting an error because of an Option Strict issue...
    VB Code:
    1. ds.DrawStyle = [Enum].Parse(GetType(DrawMode), Trim(props(0))) '<--ERROR
    2.     c = Trim(props(1))
    3.     If Not IsNumeric(c) Then
    4.         ds.PanelColor1 = Color.FromKnownColor([Enum].Parse(GetType(KnownColor), c)) '<---ERROR
    5.     Else
    6.         ds.PanelColor1 = Color.FromArgb(Convert.ToInt32(c))
    7.     End If
    8.     c = Trim(props(2))
    9.     If Not IsNumeric(c) Then
    10.         ds.PanelColor2 = Color.FromKnownColor([Enum].Parse(GetType(KnownColor), c)) '<---ERROR
    11.     Else
    12.         ds.PanelColor2 = Color.FromArgb(Convert.ToInt32(c))
    13.     End If
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    If I take the Option Strict Off then it works (see bottom of message) but I would like
    to get it converted correctly so I can leave it on.

    I guess I mixed something up. It expands correctly finally but its attached to
    my gradientpanel class which the properties are in.
    So I get all the properties of a panel object and my two panelcolor1 and 2 props.

    Cant I just have the assignment of the props and not have to use the class?
    My issues are in the DrawStyles class (actually GradientPanel class).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Expandable Properties

    This should fix your Option Strict Problems
    VB Code:
    1. Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
    2.         If value.GetType() Is GetType(String) Then
    3.             Try
    4.                 ' Attempt to parse the string representation
    5.                 ' into the constituent properties
    6.                 Dim ds As New DrawStyles
    7.                 Dim s As String = [B]CType(value, String)[/B]
    8.                 Dim c As String
    9.  
    10.                 Dim props As String() = s.Split(",".ToCharArray())
    11.  
    12.                 ds.DrawMode = [b]CType([Enum].Parse(GetType(DrawMode), Trim(props(0))), DrawMode)[/b]
    13.                 c = Trim(props(1))
    14.                 If Not IsNumeric(c) Then
    15.                     ds.Color1 = Color.FromKnownColor([B]CType([Enum].Parse(GetType(KnownColor), c), KnownColor)[/b])
    16.                 Else
    17.                     ds.Color1 = Color.FromArgb(Convert.ToInt32(c))
    18.                 End If
    19.                 c = Trim(props(2))
    20.                 If Not IsNumeric(c) Then
    21.                     ds.Color2 = Color.FromKnownColor([b]CType([Enum].Parse(GetType(KnownColor), c), KnownColor)[/b])
    22.                 Else
    23.                     ds.Color2 = Color.FromArgb(Convert.ToInt32(c))
    24.                 End If
    25.  
    26.                 Return ds
    27.  
    28.             Catch ex As Exception
    29.                 ' Revert back to the last good value if an error is encountered
    30.                 ' trying to parse the entered "text" value for the constiuent properties
    31.                 Return m_lastValue
    32.  
    33.             End Try
    34.         End If
    35.         MyBase.ConvertFrom(context, culture, value)
    36.     End Function
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  13. #13
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Expandable Properties

    Cant I just have the assignment of the props and not have to use the class?
    My issues are in the DrawStyles class (actually GradientPanel class).
    I would think that you would need to create a DrawStyles Class with just the properties you want exposed and have that as a property of GradiendPanel.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  14. #14

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    You mean that the whole drawstyles class would be a property of the gradientpanel?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    I think part of the problem is the both DrawStyles and DrawMode areReserved enumerations and they are conflicting
    with my property. Guess a naming change is in order.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    Getting allot closer, but I still cant get this line to convert correctly.
    VB Code:
    1. gs.GradientMode = [Enum].Parse(GetType(GradientStyle), Trim(props(0)))
    When I wrap it with the CType it tells me that the GradientStyle is undefined?
    VB Code:
    1. gs.GradientMode = CType([Enum].Parse(GetType(GradientStyle), Trim(props(0))), GradientStyle)
    What am I doing wrong?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties

    Duh! I figured out! I needed to ctype it to a lineargradientmode and not a class.
    VB Code:
    1. gs.GradientMode = CType([Enum].Parse(GetType(GradientStyle), Trim(props(0))), LinearGradientMode)
    Now I have two issues left.
    1. Defaults are not Resetting to the correct values. I have the default attributes on each of the
      three properties but when I reset them it goes to Horizontal, 0, 0 and not ForwardDiagonal, White, Blue.

      Do I need to supply something different as a default since the prop is expandable?


    2. The gradient panel is not respondin at all to the property changes.
    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties - Almost Solved but still a few "issues"

    Ok, now I get some kind of hex number for RGB colors?

    "ForwardDiagonal, ff7ba2e7, ff6375d6"

    I am trying to get the Reset right click context menu to function at the DrawStyles level just like it does
    for the Font property. The Font property lets you reset all the child properties at the top level with one
    click.

    I have the GradientMode, PanelColor1, and PanelColor2 all with the DefaultValues attrib, so I dont know
    what else to do to fix it?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Expandable Properties - Almost Solved but still a few "issues"

    VB Code:
    1. Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destType As Type) As Object
    2.       If destType Is GetType(String) Then
    3.          ' Attempt to convert the value into a string representation
    4.          Try
    5.             Dim styles As DrawStyles = CType(value, DrawStyles)
    6.             m_lastValue = styles
    7.             [b]Return String.Format("{0}, {1}, {2}", styles.DrawMode, styles.Color1.Name, styles.Color2.Name)[/b]
    8.  
    9.          Catch ex As Exception
    10.             ' If there was an error, display it instead of the string value
    11.             Return String.Format("Error: {0}", ex.Message)
    12.  
    13.          End Try
    14.       End If
    15.       Return MyBase.ConvertTo(context, culture, value, destType)
    16.    End Function
    17. End Class

    The problem with the colors displaying as hex should be on the bold line.

    -----
    Default values:

    VB Code:
    1. Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
    2.       If value.GetType() Is GetType(String) Then
    3.          [b]If IsNothing(Value) OrElse DirectCast(Value,String).Text.Length = 0 Then
    4.                  Dim x as New DrawStyles
    5.  
    6.                  x.DrawMode = Vertical
    7.                  x.Color1 = Color.White
    8.                  x.Color2 = Color.Blue
    9.                
    10.                  Return x
    11.          End If[/b]
    12.          Try
    13.             ' Attempt to parse the string representation
    14.             ' into the constituent properties
    15.             Dim ds As New DrawStyles
    16.             Dim s As String = value
    17.             Dim c As String
    18.  
    19.             Dim props As String() = s.Split(",".ToCharArray())
    20.  
    21.             ds.DrawMode = [Enum].Parse(GetType(DrawMode), Trim(props(0)))
    22.             c = Trim(props(1))
    23.             If Not IsNumeric(c) Then
    24.                ds.Color1 = Color.FromKnownColor([Enum].Parse(GetType(KnownColor), c))
    25.             Else
    26.                ds.Color1 = Color.FromArgb(Convert.ToInt32(c))
    27.             End If
    28.             c = Trim(props(2))
    29.             If Not IsNumeric(c) Then
    30.                ds.Color2 = Color.FromKnownColor([Enum].Parse(GetType(KnownColor), c))
    31.             Else
    32.                ds.Color2 = Color.FromArgb(Convert.ToInt32(c))
    33.             End If
    34.  
    35.             Return ds
    36.  
    37.          Catch ex As Exception
    38.             ' Revert back to the last good value if an error is encountered
    39.             ' trying to parse the entered "text" value for the constiuent properties
    40.             Return m_lastValue
    41.  
    42.          End Try
    43.       End If
    44.       MyBase.ConvertFrom(context, culture, value)
    45.    End Function

    I think that should do the trick
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  20. #20

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties - Almost Solved but still a few "issues"

    On ConvertFrom procedure I get an error stating that Text is not a member of string
    VB Code:
    1. If IsNothing(value) OrElse DirectCast(value, String).Text.Length = 0 Then
    2.  
    3. 'Would this be the same thing?
    4. If IsNothing(value) OrElse DirectCast(value, String).ToString.Length = 0 Then
    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Expandable Properties - Almost Solved but still a few "issues"

    I spaced...

    VB Code:
    1. If IsNothing(value) OrElse DirectCast(value, String).Length = 0 Then

    for some reason I was thinking it was a textbox
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  22. #22

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties - Almost Solved but still a few "issues"

    Cool getting even closer. But the top level prop only reset if I delete the concatinated string, but then it
    reset correctly. When I reset the top level prop it resets to horizontal, 0, 0 and not my custom defaults I
    added to each of the three child props. Do I need to add the defaults to the top level mailn prop too? Idf so
    then how since you cant have more then one?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  23. #23
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Expandable Properties - Almost Solved but still a few "issues"

    To properly implement the reset you'll need to add the ShouldSerialize and Reset methods for the expandable class, see my example for details.

  24. #24

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties - Almost Solved but still a few "issues"

    I have everything from your example, but only the child properties reset properly.

    This is what I have in my user control main class. Do I need to put a default on this one fall all?

    VB Code:
    1. <Browsable(True), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
    2.         Category("MyPanel")> _
    3.         Public Property DrawStyle() As GradientStyle
    4.             Get
    5.                 Return _GradientStyle
    6.             End Get
    7.             Set(ByVal Value As GradientStyle)
    8.                 _GradientStyle = Value
    9.                 MyBase.Refresh()
    10.             End Set
    11.         End Property
    12.  
    13.         Private Function ShouldSerializeDrawStyle() As Boolean
    14.             ' Return True to indicate the value is not default and should be persisted
    15.             Return Not (_GradientStyle.GradientMode = LinearGradientMode.ForwardDiagonal AndAlso _GradientStyle.PanelColor1.Equals(Color.FromArgb(255, 200, 0)) AndAlso _GradientStyle.PanelColor2.Equals(Color.FromArgb(88, 88, 88)))
    16.         End Function
    17.  
    18.         Private Sub ResetDrawStyle()
    19.             ' Reset the property to a default value
    20.             _GradientStyle = New GradientStyle
    21.         End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  25. #25

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties - Almost Solved but still a few "issues"

    Ok, still getting the hex values for rgb color values. Wouldnt the Else condition be what I need to fix?
    VB Code:
    1. 'ConvertFrom procedure...
    2.  
    3. If Not IsNumeric(c) Then
    4.     gs.PanelColor1 = Color.FromKnownColor(CType([Enum].Parse(GetType(KnownColor), c), KnownColor))
    5. Else
    6.     gs.PanelColor1 = Color.FromArgb(Convert.ToInt32(c)) 'Is this changing it to a hex number?
    7. End If
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  26. #26
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Expandable Properties - Almost Solved but still a few "issues"

    VB Code:
    1. Color.FromArgb(Convert.ToInt32(c))

    Returns a Color not a Integer, so I dont thin that would be the problem.


    -----

    Heres what I think is happening

    VB Code:
    1. Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destType As Type) As Object
    2.       If destType Is GetType(String) Then
    3.          ' Attempt to convert the value into a string representation
    4.          Try
    5.             Dim styles As DrawStyles = CType(value, DrawStyles)
    6.             m_lastValue = styles
    7.             [b]Return String.Format("{0}, {1}, {2}", styles.DrawMode, styles.Color1.Name, styles.Color2.Name)[/b]
    8.  
    9.          Catch ex As Exception
    10.             ' If there was an error, display it instead of the string value
    11.             Return String.Format("Error: {0}", ex.Message)
    12.  
    13.          End Try
    14.       End If
    15.       Return MyBase.ConvertTo(context, culture, value, destType)
    16.    End Function
    17. End Class

    I think the problem is that when sytles.Color2 was assigned by Color.FromArgb(....) the integer does not represent a "KnownColor" so it can't name the color therefore it returns the hex value of the color.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  27. #27

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties - Almost Solved but still a few "issues"

    Ok, I think I see what you mean. If its a RGB color there is no known color so the name will fail so it
    stays as an hex value. So how do I fix that? Something like testing it for a known color name and if it
    doesnt match then change it to a rgb value. How?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  28. #28

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties - Almost Solved but still a few "issues"

    So when I take the .Name property off I get this for the top level parent property.
    VB Code:
    1. DrawStyle | Horizontal, Color [A=255, R=255, G=128, B=128], Color [A=255, R=128, G=255, B=128]
    So how do I go about converting it to be like:
    VB Code:
    1. DrawStyle | Horizontal, 255, 128, 128,  128, 255, 128
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  29. #29

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Properties - Almost Solved

    *BUMP*

    I just need to first get the color rgb conversion solved in the ConvertTo and ConvertFrom procedures.
    Then I will work on the panel painting correclty issue.


    Any help is appreciated.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  30. #30
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Expandable Props - Color conversion issue - 6 Reps to the first who can solve it!

    VB Code:
    1. Option Strict On
    2. Option Explicit On
    3.  
    4. Public Class ARGBColor
    5.  
    6. #Region " Member Variables "
    7.     Private _Red As Byte
    8.     Private _Blue As Byte
    9.     Private _Green As Byte
    10.     Private _Alpha As Byte
    11. #End Region
    12.  
    13. #Region " Properties "
    14.     Public Property Red() As Byte
    15.         Get
    16.             Return _Red
    17.         End Get
    18.         Set(ByVal Value As Byte)
    19.             _Red = Value
    20.         End Set
    21.     End Property
    22.     Public Property Blue() As Byte
    23.         Get
    24.             Return _Blue
    25.         End Get
    26.         Set(ByVal Value As Byte)
    27.             _Blue = Value
    28.         End Set
    29.     End Property
    30.     Public Property Green() As Byte
    31.         Get
    32.             Return _Green
    33.         End Get
    34.         Set(ByVal Value As Byte)
    35.             _Green = Value
    36.         End Set
    37.     End Property
    38.     Public Property Alpha() As Byte
    39.         Get
    40.             Return _Alpha
    41.         End Get
    42.         Set(ByVal Value As Byte)
    43.             _Alpha = Value
    44.         End Set
    45.     End Property
    46. #End Region
    47.  
    48. #Region " Constructors "
    49.     Public Sub New()
    50.     End Sub
    51.  
    52.     Public Sub New(ByVal ARGBColor As Integer)
    53.         Dim bytValue() As Byte = BitConverter.GetBytes(ARGBColor)
    54.  
    55.         _Red = bytValue(0)
    56.         _Blue = bytValue(1)
    57.         _Green = bytValue(2)
    58.         _Alpha = bytValue(3)
    59.     End Sub
    60.  
    61.     Public Sub New(ByVal Red As Byte, ByVal Blue As Byte, ByVal Green As Byte, ByVal Alpha As Byte)
    62.         _Red = Red
    63.         _Blue = Blue
    64.         _Green = Green
    65.         _Alpha = Alpha
    66.     End Sub
    67. #End Region
    68.  
    69. #Region " ConvertTo Methods "
    70.  
    71.     Public Function ToColor() As System.Drawing.Color
    72.         Return System.Drawing.Color.FromArgb(ToInteger)
    73.     End Function
    74.  
    75.     Public Function ToInteger() As Integer
    76.         Return BitConverter.ToInt32(New Byte() {_Red, _Blue, _Green, _Alpha}, 0)
    77.     End Function
    78.  
    79.     Public Overrides Function ToString() As String
    80.         Return String.Format("R={0}, B={2}, G={1}, A={3}", Red, Blue, Green, Alpha)
    81.     End Function
    82.  
    83. #End Region
    84.  
    85. #Region " ConvertFrom Methods "
    86.  
    87.     Public Shared Function FromColor(ByVal Color As System.Drawing.Color) As ARGBColor
    88.         Return FromInteger(Color.ToArgb)
    89.     End Function
    90.  
    91.     Public Shared Function FromInteger(ByVal Color As Integer) As ARGBColor
    92.         Dim bytColor() As Byte = BitConverter.GetBytes(Color)
    93.  
    94.         Dim x As New ARGBColor(bytColor(0), bytColor(1), bytColor(2), bytColor(3))
    95.  
    96.         Return x
    97.  
    98.     End Function
    99.  
    100. #End Region
    101.  
    102. End Class

    This class should help you easily convert from color to A/RGB

    I would suggest testing using this :

    VB Code:
    1. Public Shared Function IsKnownColor(ByVal Color As System.Drawing.Color) As Boolean
    2.         Return [Enum].IsDefined(GetType(System.Drawing.KnownColor), Color.Name)
    3.     End Function

    If IsKnownColor is True Then Use the Color.Name property
    If IsKnownColor is False Then use ARGBColor.FromColor(Color).ToString ' or apply custom formatting
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  31. #31
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Expandable Props - Color conversion issue - 6 Reps to the first who can solve it!!!

    If the property is already a Color type, then you don't need to bother converting the ARGB value into it's components, instead you can access them via the R, G, B properties, here's an example using the DrawingStyles sample I posted previously:
    VB Code:
    1. Imports System.ComponentModel
    2. Imports System.Globalization
    3.  
    4. ' Expandable TypeConverter for the DrawStyles class
    5. Public Class DrawStylesConverter
    6.    Inherits ExpandableObjectConverter
    7.  
    8.    Private m_lastValue As DrawStyles = New DrawStyles
    9.  
    10.    Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal t As Type) As Boolean
    11.       ' Indicate which types this class can convert "From"
    12.       If t Is GetType(String) Then
    13.          Return True
    14.       End If
    15.       Return MyBase.CanConvertFrom(context, t)
    16.    End Function
    17.  
    18.    Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
    19.       If value.GetType() Is GetType(String) Then
    20.          Try
    21.             ' Attempt to parse the string representation
    22.             ' into the constituent properties
    23.             Dim ds As New DrawStyles
    24.             Dim s As String = value
    25.             Dim c As String
    26.             Dim i As Integer
    27.  
    28.             Dim props As String() = s.Split(",".ToCharArray())
    29.  
    30.             ds.DrawMode = [Enum].Parse(GetType(DrawMode), Trim(props(0)))
    31.             c = Trim(props(1))
    32.             If Not IsNumeric(c) Then
    33.                ds.Color1 = Color.FromKnownColor([Enum].Parse(GetType(KnownColor), c))
    34.                i = 2
    35.             Else
    36.                ds.Color1 = Color.FromArgb(Convert.ToInt32(c), Convert.ToInt32(Trim(props(2))), Convert.ToInt32(Trim(props(3))))
    37.                i = 4
    38.             End If
    39.             c = Trim(props(i))
    40.             If Not IsNumeric(c) Then
    41.                ds.Color2 = Color.FromKnownColor([Enum].Parse(GetType(KnownColor), c))
    42.             Else
    43.                ds.Color2 = Color.FromArgb(Convert.ToInt32(c), Convert.ToInt32(Trim(props(i + 1))), Convert.ToInt32(Trim(props(i + 2))))
    44.             End If
    45.  
    46.             Return ds
    47.  
    48.          Catch ex As Exception
    49.             ' Revert back to the last good value if an error is encountered
    50.             ' trying to parse the entered "text" value for the constiuent properties
    51.             Return m_lastValue
    52.  
    53.          End Try
    54.       End If
    55.       MyBase.ConvertFrom(context, culture, value)
    56.    End Function
    57.  
    58.    Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal t As Type) As Boolean
    59.       ' Indicate which types this class can convert "To"
    60.       If t Is GetType(DrawStyles) Then Return True
    61.       Return MyBase.CanConvertTo(context, t)
    62.    End Function
    63.  
    64.    Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destType As Type) As Object
    65.       If destType Is GetType(String) Then
    66.          ' Attempt to convert the value into a string representation
    67.          Try
    68.             Dim styles As DrawStyles = CType(value, DrawStyles)
    69.             m_lastValue = styles
    70.             Return String.Format("{0}, {1}, {2}", styles.DrawMode, ColorToString(styles.Color1), ColorToString(styles.Color2))
    71.  
    72.          Catch ex As Exception
    73.             ' If there was an error, display it instead of the string value
    74.             Return String.Format("Error: {0}", ex.Message)
    75.  
    76.          End Try
    77.       End If
    78.       Return MyBase.ConvertTo(context, culture, value, destType)
    79.    End Function
    80.  
    81.    Private Function ColorToString(ByVal theColor As Color)
    82.       ' Converts a Color into an appropriately formatted string
    83.       ' For Known Colors the name is returned, otherwise the RGB value is returned
    84.       ' in the format "R, G, B"
    85.       If Not [Enum].IsDefined(GetType(KnownColor), theColor.Name) Then
    86.          Return String.Format("{0}, {1}, {2}", theColor.R, theColor.G, theColor.B)
    87.       Else
    88.          Return theColor.Name
    89.       End If
    90.    End Function
    91. End Class
    This formats an unknow color in the format; "<R>, <G>, <B>" and returns the Name of a Known Color.

    One thing to note; a possible drawback of formatting the RGB value with comma's is that you're using comma's as a sub-property delimiter, so it makes the parsing a little trickier and may not be as readable to the user.

  32. #32

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Props - Minor Property conversion issue

    Ok, so far I got Aarons code working but its not working when you type the drawstyle or known colors
    into the parent property: DrawStyles

    Is there something else I need to do to get the typed text like "Horizontal, Red, Green" accepted in the top property?

    Also, the reset at the parent property level resets the props to Horizontal, 0, 0, 0, 0, 0, 0.

    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  33. #33
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Expandable Props - Minor Property conversion issue

    The code as I've posted works fine when entering the text equivelent of the sub property values into the parent property field.

    Maybe it's something in the way you've altered it to fit your control?

    Can you post the code for the Convertor as it appears in your control?

    As for the reset, that's handled by the ShouldSerialize and Reset supporting methods of the property in the Control.

    If you'd rather not post the code here, I'd be happy to take a look at it outside the forums.

    Regards,

    - Aaron.

  34. #34

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Props - Minor Property conversion issue

    Ok, I can post this part since it parallels yours and is not specific. Here is the expandable prop class.
    Its part of a namespace that I am importing into my UC class. Not too
    sure if that makes a difference?
    Also, I changed the name of the class to GradientStyle instead of DrawStyle

    VB Code:
    1. '...
    2.     '...
    3.     '...
    4.     End Class
    5.  
    6.     ' Expandable TypeConverter for the DrawStyles class
    7.     Public Class GradientStyleConverter
    8.  
    9.         Inherits ExpandableObjectConverter
    10.  
    11.         Private m_lastValue As GradientStyle = New GradientStyle
    12.  
    13.         Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal t As Type) As Boolean
    14.             ' Indicate which types this class can convert "From"
    15.             If t Is GetType(String) Then
    16.                 Return True
    17.             End If
    18.             Return MyBase.CanConvertFrom(context, t)
    19.         End Function
    20.  
    21.         Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
    22.             If value.GetType() Is GetType(String) Then
    23.                 Try
    24.                     ' Attempt to parse the string representation
    25.                     ' into the constituent properties
    26.                     Dim gs As New GradientStyle
    27.                     Dim s As String = CType(value, String)
    28.                     Dim c As String
    29.                     Dim i As Integer
    30.                     Dim props As String() = s.Split(",".ToCharArray())
    31.                     gs.GradientMode = CType([Enum].Parse(GetType(GradientStyle), Trim(props(0))), LinearGradientMode)
    32.                     c = Trim(props(1))
    33.                     If Not IsNumeric(c) Then
    34.                         gs.PanelColor1 = Color.FromKnownColor(CType([Enum].Parse(GetType(KnownColor), c), KnownColor))
    35.                         i = 2
    36.                     Else
    37.                         gs.PanelColor1 = Color.FromArgb(Convert.ToInt32(c), Convert.ToInt32(Trim(props(2))), Convert.ToInt32(Trim(props(3))))
    38.                         i = 4
    39.                     End If
    40.                     c = Trim(props(i))
    41.                     If Not IsNumeric(c) Then
    42.                         gs.PanelColor2 = Color.FromKnownColor(CType([Enum].Parse(GetType(KnownColor), c), KnownColor))
    43.                     Else
    44.                         gs.PanelColor2 = Color.FromArgb(Convert.ToInt32(c), Convert.ToInt32(Trim(props(i + 1))), Convert.ToInt32(Trim(props(i + 2))))
    45.                     End If
    46.                     Return gs
    47.  
    48.                 Catch ex As Exception
    49.                     ' Revert back to the last good value if an error is encountered
    50.                     ' trying to parse the entered "text" value for the constiuent properties
    51.                     Return m_lastValue
    52.                 End Try
    53.             End If
    54.             MyBase.ConvertFrom(context, culture, value)
    55.         End Function
    56.  
    57.         Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal t As Type) As Boolean
    58.             ' Indicate which types this class can convert "To"
    59.             If t Is GetType(GradientStyle) Then Return True
    60.             Return MyBase.CanConvertTo(context, t)
    61.         End Function
    62.  
    63.         Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destType As Type) As Object
    64.             If destType Is GetType(String) Then
    65.                 ' Attempt to convert the value into a string representation
    66.                 Try
    67.                     Dim styles As GradientStyle = CType(value, GradientStyle)
    68.                     m_lastValue = styles
    69.                     Return String.Format("{0}, {1}, {2}", styles.GradientMode, ColorToString(styles.PanelColor1), ColorToString(styles.PanelColor2))
    70.                 Catch ex As Exception
    71.                     ' If there was an error, display it instead of the string value
    72.                     Return String.Format("Error: {0}", ex.Message)
    73.                 End Try
    74.             End If
    75.             Return MyBase.ConvertTo(context, culture, value, destType)
    76.         End Function
    77.  
    78.         Private Function ColorToString(ByVal theColor As Color) As String
    79.             ' Converts a Color into an appropriately formatted string
    80.             ' For Known Colors the name is returned, otherwise the RGB value is returned
    81.             ' in the format "R, G, B"
    82.             If Not [Enum].IsDefined(GetType(KnownColor), theColor.Name) Then
    83.                 Return String.Format("{0}, {1}, {2}", theColor.R, theColor.G, theColor.B)
    84.             Else
    85.                 Return theColor.Name
    86.             End If
    87.         End Function
    88.  
    89.     End Class
    90.  
    91. End Namespace
    I think the code is good and the issue is perhaps in either the GradientPanel or UC classes.

    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  35. #35
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Expandable Props - Minor Property conversion issue

    The problem lies in the ConvertFrom method where you're assigning the GradientMode.
    The Enumeration is being passed the Gradient class type instead of the LinearGradientMode Enumeration type.

    This:
    VB Code:
    1. gs.GradientMode = CType([Enum].Parse(GetType(GradientStyle), Trim(props(0))), LinearGradientMode)
    Should Be This:
    VB Code:
    1. gs.GradientMode = CType([Enum].Parse(GetType(LinearGradientMode), Trim(props(0))), LinearGradientMode)
    Regards,

    - Aaron.

  36. #36

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Props - Minor Property conversion issue

    w00t, w00t! Success You saved the day yet again. Thanks a million!

    Now since I had taken a break from this project its time to move on to the next issue.


    For some reason (probably someting that I missed again) the panel does not change graphics when the properties
    are changed.

    With the regular properties I had this working. Now that the expandable props are in place I need to hook
    the actual drawing back up. I think it may be because there may be different instances of classes being created?

    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  37. #37
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Expandable Props - Minor Drawing/Coloring Issue

    Took a while to track down, but it looks like you need to implement a few more methods in the ExpandableObjectConverter,
    in particular the CreateInstance method, which seems to be called whenever the sub-properties are changed,
    triggering a change in the Expandable proeprty which can be intercepted and reacted to.

    You'll need to tweak this a little, I didn't recognize the LinearGradientMode enum,
    so I mocked up my own.

    VB Code:
    1. Imports System.ComponentModel
    2. Imports System.Globalization
    3.  
    4. ' Expandable TypeConverter for the DrawStyles class
    5. Public Class GradientStyleConverter
    6.  
    7.    Inherits ExpandableObjectConverter
    8.  
    9.    Private m_lastValue As GradientStyle = New GradientStyle
    10.  
    11.    Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal t As Type) As Boolean
    12.       ' Indicate which types this class can convert "From"
    13.       If t Is GetType(String) Then
    14.          Return True
    15.       End If
    16.       Return MyBase.CanConvertFrom(context, t)
    17.    End Function
    18.  
    19.    Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
    20.       If value.GetType() Is GetType(String) Then
    21.          Try
    22.             ' Attempt to parse the string representation
    23.             ' into the constituent properties
    24.             Dim gs As New GradientStyle
    25.             Dim s As String = CType(value, String)
    26.             Dim c As String
    27.             Dim i As Integer
    28.             Dim props As String() = s.Split(",".ToCharArray())
    29.             gs.GradientMode = CType([Enum].Parse(GetType(LinearGradientMode), Trim(props(0))), LinearGradientMode)
    30.             c = Trim(props(1))
    31.             If Not IsNumeric(c) Then
    32.                gs.PanelColor1 = Color.FromKnownColor(CType([Enum].Parse(GetType(KnownColor), c), KnownColor))
    33.                i = 2
    34.             Else
    35.                gs.PanelColor1 = Color.FromArgb(Convert.ToInt32(c), Convert.ToInt32(Trim(props(2))), Convert.ToInt32(Trim(props(3))))
    36.                i = 4
    37.             End If
    38.             c = Trim(props(i))
    39.             If Not IsNumeric(c) Then
    40.                gs.PanelColor2 = Color.FromKnownColor(CType([Enum].Parse(GetType(KnownColor), c), KnownColor))
    41.             Else
    42.                gs.PanelColor2 = Color.FromArgb(Convert.ToInt32(c), Convert.ToInt32(Trim(props(i + 1))), Convert.ToInt32(Trim(props(i + 2))))
    43.             End If
    44.             Return gs
    45.  
    46.          Catch ex As Exception
    47.             ' Revert back to the last good value if an error is encountered
    48.             ' trying to parse the entered "text" value for the constiuent properties
    49.             Return m_lastValue
    50.          End Try
    51.       End If
    52.       MyBase.ConvertFrom(context, culture, value)
    53.    End Function
    54.  
    55.    Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, ByVal t As Type) As Boolean
    56.       ' Indicate which types this class can convert "To"
    57.       If t Is GetType(GradientStyle) Then Return True
    58.       Return MyBase.CanConvertTo(context, t)
    59.    End Function
    60.  
    61.    Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destType As Type) As Object
    62.       If destType Is GetType(String) Then
    63.          ' Attempt to convert the value into a string representation
    64.          Try
    65.             Dim styles As GradientStyle = CType(value, GradientStyle)
    66.             m_lastValue = styles
    67.             Return String.Format("{0}, {1}, {2}", styles.GradientMode, ColorToString(styles.PanelColor1), ColorToString(styles.PanelColor2))
    68.          Catch ex As Exception
    69.             ' If there was an error, display it instead of the string value
    70.             Return String.Format("Error: {0}", ex.Message)
    71.          End Try
    72.       End If
    73.       Return MyBase.ConvertTo(context, culture, value, destType)
    74.    End Function
    75.  
    76.    Public Overloads Overrides Function GetPropertiesSupported(ByVal context As ITypeDescriptorContext) As Boolean
    77.       ' Indicate the we support returning a list
    78.       ' of the properties this type contains
    79.       Return True
    80.    End Function
    81.  
    82.    Public Overloads Overrides Function GetProperties(ByVal context As ITypeDescriptorContext, ByVal value As Object, ByVal attributes As Attribute()) As PropertyDescriptorCollection
    83.       ' Return a collection of the Properties that make up this type
    84.       Dim collection As PropertyDescriptorCollection = TypeDescriptor.GetProperties(GetType(GradientStyle), attributes)
    85.       Dim props As String() = New String() {"GradientMode", "PanelColor1", "PanelColor2"}
    86.       Return collection.Sort(props)
    87.    End Function
    88.  
    89.    Public Overloads Overrides Function GetCreateInstanceSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
    90.       ' Indicate that creating an instance is supported
    91.       Return True
    92.    End Function
    93.  
    94.    Public Overloads Overrides Function CreateInstance(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal propertyValues As System.Collections.IDictionary) As Object
    95.       ' Create a new instance of the Gradient Style
    96.       ' with the supplied property values
    97.       Dim obj1 As Object = propertyValues("GradientMode")
    98.       Dim obj2 As Object = propertyValues("PanelColor1")
    99.       Dim obj3 As Object = propertyValues("PanelColor2")
    100.  
    101.       If obj1 Is Nothing Then obj1 = LinearGradientMode.Mode1
    102.       If obj2 Is Nothing Then obj1 = Color.Red
    103.       If obj3 Is Nothing Then obj1 = Color.Blue
    104.  
    105.       Dim gs As New GradientStyle
    106.       gs.GradientMode = obj1
    107.       gs.PanelColor1 = obj2
    108.       gs.PanelColor2 = obj3
    109.  
    110.       Return gs
    111.    End Function
    112.  
    113.    Private Function ColorToString(ByVal theColor As Color) As String
    114.       ' Converts a Color into an appropriately formatted string
    115.       ' For Known Colors the name is returned, otherwise the RGB value is returned
    116.       ' in the format "R, G, B"
    117.       If Not [Enum].IsDefined(GetType(KnownColor), theColor.Name) Then
    118.          Return String.Format("{0}, {1}, {2}", theColor.R, theColor.G, theColor.B)
    119.       Else
    120.          Return theColor.Name
    121.       End If
    122.    End Function
    123. End Class
    Then you should just need to make a call to Invalidate or whatever you call to repaint your control, i.e.
    VB Code:
    1. <Browsable(True), _
    2.     DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    3.    Public Property GradientStyle() As GradientStyle
    4.       Get
    5.          Return _gradientStyle
    6.       End Get
    7.       Set(ByVal Value As GradientStyle)
    8.          _gradientStyle = Value
    9.          Me.Invalidate()
    10.       End Set
    11.    End Property
    Regards,

    - Aaron.

  38. #38

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Props - Minor Drawing/Coloring Issue

    Ok, I think I am following you but for some reason I dont have anything available in my props.
    No MyBase.Refresh, MyBase.Invalidate, MyBase.Update, Me.Refresh, Me.Invalidate, Me.Update.

    Also, why do some of the procedures do nothing other then Return True?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  39. #39
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Re: Expandable Props - Minor Drawing/Coloring Issue

    If you're control is inheriting from UserControl or Control it
    should have an Invalidate method which triggers a Paint event.

    Either way, it doesn't matter, you must have something in your control
    that gets called when you want it to draw itself, if so, then that's what you want
    to call in the Set of the expandable property in your control.

    Those methods that just return True are called by the IDE to see if your
    class supports certain things, like supplying a list of the sub-properties and
    creating instances of your class.

    Regards,

    - Aaron.

    Edit: Re-reading your post makes me think that maybe you thought the Invalidate call would be in the converter class, it's not,
    it's in your UserControl when you expose the property of type GradientStyle. - Aaron.
    Last edited by Aaron Young; Apr 1st, 2005 at 11:26 PM.

  40. #40

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Expandable Props - Minor Drawing/Coloring Issue

    Ok, I think I found whats wrong.

    I have these three classes in one class file wrapped by a namespace and this namespace is being imported into the user control base.

    The first class is the one (GradientPanel) that is inheriting the panel control and is where I am overridding the OnPaint event
    to draw the gradient.

    The second one (GradientStyle) is the one that has the 3 properties (DrawMode, PanelColor1, and PanelColor2). This one has the typeconverter (GradientStyleConverter) atribute.

    The third one (GradientStyleConverter) is the one that inherits the ExpandableObjectConverter.


    I think the first and second classes need to be in the same class and not separate?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width