Results 1 to 37 of 37

Thread: [RESOLVED] TypeConverter?

  1. #1

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Resolved [RESOLVED] TypeConverter?

    Hi everyone, I have a UserControl that I want to show some of its properties whit the percentage char like (100%) so I created a class that inherits from TypeConverter class. For some reason it doesn’t work see the image. What could be the problem?
    Thanks in advance!

    Here is the class:
    vb Code:
    1. Public Class PercentageConverter
    2.         Inherits TypeConverter
    3.  
    4.         Public Sub New()
    5.  
    6.         End Sub
    7.  
    8.         Public Overloads Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
    9.             If sourceType Is GetType(String) Then
    10.                 Return True
    11.             End If
    12.             Return MyBase.CanConvertFrom(context, sourceType)
    13.         End Function
    14.  
    15.         Public Overloads Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
    16.             If TypeOf value Is String Then
    17.                 Dim s As String
    18.                 s = CStr(value)
    19.                 If s.EndsWith("%") Then
    20.                     s = (CStr(value)).Substring(0, (CStr(value)).Length - 1)
    21.                 End If
    22.                 Return Double.Parse(s, NumberStyles.Any, culture) / 100
    23.             End If
    24.             Return MyBase.ConvertFrom(context, culture, value)
    25.         End Function
    26.  
    27.         Public Overloads Overrides Function ConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object, ByVal destinationType As System.Type) As Object
    28.             If destinationType Is GetType(String) Then
    29.                 Dim v As Double
    30.                 v = CDbl(value) * 100
    31.                 Return CStr(v) & "%"
    32.             End If
    33.             Return MyBase.ConvertTo(context, culture, value, destinationType)
    34.         End Function
    35.  
    36.     End Class
    and this is how i use it:
    vb Code:
    1. ''' <summary>
    2.     ''' Gets or sets the size of the center-point that is directly proportional to the circumference of the clock.
    3.     ''' </summary>
    4.     <DefaultValue(0.03R), TypeConverterAttribute(GetType(PercentageConverter)), _
    5.     Bindable(True), Category("Layout"), Description( _
    6.     "Indicates the size of the center-point that is directly proportional to the circumference of the clock.")> _
    7.       Public Property CenterPointSize() As Double
    8.         '<DebuggerHidden()> _
    9.         Get
    10.             Return Me._centerPointRatio
    11.         End Get
    12.         '<DebuggerHidden()> _
    13.         Set(ByVal value As Double)
    14.             If Not Me._centerPointRatio.Equals(value) Then
    15.                 If value < 0 Or value > 1 Then
    16.                     Throw New Exception("The value should be in the range of 0 to 100.")
    17.                 Else
    18.                     Me._centerPointRatio = value
    19.                     Me.SetCenterPointPath()
    20.                     Me.ClockPanel.Invalidate()
    21.                     Me.ClockPanel.Update()
    22.                 End If
    23.             End If
    24.         End Set
    25.     End Property
    Attached Images Attached Images  

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: TypeConverter?

    I haven't looked too closely at your code but I suggest that you open .NET Reflector and take a look at a property that does just that, like the Form.Opacity property. It uses the OpacityConverter class, which you could basically copy.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    Hi Jmc, and thanks for the suggestion. Yes this converter should be exactly as the opacity converter. I am not familiar with the .Net Reflector; can you tell me how to open it? Thanks

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: TypeConverter?

    You have to download an install .NET Reflector before you can open it, but it's an essential tool for all .NET developers. Just Google it and you find the download. Once you run it you just navigate to the types and members you're interested in and it will show you how they are implemented.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    I downloaded it and now I am looking in the Windows.Forms.dll but I am not sure where to look in there. Do you know where it might be by the chance? This is a great tool thank you very much.

  6. #6

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    Never mind I found it. Thank you very much Jmc! Once again you are a life sever. This thing doesn’t let me give you rep but I promise I will get back to this later time.

  7. #7

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    I copied the exact code but the result is the same (the property is enabled). But when I use OpacityConverter class it works. Is there some attribute I am missing?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: TypeConverter?

    You presumably mustn't have used the exact code because I just did and it worked fine. Here's the code for my test UC and PercentageConverter:
    Code:
    Imports System.ComponentModel
    Imports System.Globalization
    
    Public Class UserControl1
    
        Private _percentage As Double
    
        <TypeConverter(GetType(PercentageConverter)), DefaultValue(1.0R)> _
        Public Property Percentage() As Double
            Get
                Return Me._percentage
            End Get
            Set(ByVal value As Double)
                Me._percentage = value
            End Set
        End Property
    
    End Class
    
    
    Public Class PercentageConverter
        Inherits TypeConverter
        ' Methods
        Public Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
            Return ((sourceType Is GetType(String)) OrElse MyBase.CanConvertFrom(context, sourceType))
        End Function
    
        Public Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
            If Not TypeOf value Is String Then
                Return MyBase.ConvertFrom(context, culture, value)
            End If
            Dim s As String = CStr(value).Replace("%"c, " "c).Trim
            Dim num As Double = Double.Parse(s, CultureInfo.CurrentCulture)
            If (((CStr(value).IndexOf("%") > 0) AndAlso (num >= 0)) AndAlso (num <= 1)) Then
                s = (num / 100).ToString(CultureInfo.CurrentCulture)
            End If
            Dim num3 As Double = 1
            Try
                num3 = CDbl(TypeDescriptor.GetConverter(GetType(Double)).ConvertFrom(context, culture, s))
                If (num3 > 1) Then
                    num3 = (num3 / 100)
                End If
            Catch exception As FormatException
                Throw New FormatException("InvalidBoundArgument", exception)
            End Try
            If ((num3 < 0) OrElse (num3 > 1)) Then
                Throw New FormatException("InvalidBoundArgument")
            End If
            Return num3
        End Function
    
        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 Nothing) Then
                Throw New ArgumentNullException("destinationType")
            End If
            If (destinationType Is GetType(String)) Then
                Dim num As Double = CDbl(value)
                Dim num2 As Integer = CInt((num * 100))
                Return (num2.ToString(CultureInfo.CurrentCulture) & "%")
            End If
            Return MyBase.ConvertTo(context, culture, value, destinationType)
        End Function
    
    End Class
    The only change was that I removed the reference to the SR class, which is not available outside the System.Windows.Forms.dll assembly.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    Hmm! I tried your code but no result. For SR I just added a reference to the System.Web.Mobile and that is not a problem but still with the two examples the property is unabled. Here is the code I have now.
    vb Code:
    1. Imports System.ComponentModel
    2. Imports System.Globalization
    3. Imports System.Web.UI.MobileControls.Adapters
    4.  
    5.  
    6. Public Class PercentageConverter
    7.     Inherits TypeConverter
    8.     ' Methods
    9.  
    10.     Public Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, ByVal sourceType As Type) As Boolean
    11.         Return ((sourceType Is GetType(String)) OrElse MyBase.CanConvertFrom(context, sourceType))
    12.     End Function
    13.  
    14.     Public Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object) As Object
    15.         If Not TypeOf value Is String Then
    16.             Return MyBase.ConvertFrom(context, culture, value)
    17.         End If
    18.         Dim s As String = CStr(value).Replace("%"c, " "c).Trim
    19.         Dim num As Double = Double.Parse(s, CultureInfo.CurrentCulture)
    20.         If (((CStr(value).IndexOf("%") > 0) AndAlso (num >= 0)) AndAlso (num <= 1)) Then
    21.             s = (num / 100).ToString(CultureInfo.CurrentCulture)
    22.         End If
    23.         Dim num3 As Double = 1
    24.         Try
    25.             num3 = CDbl(TypeDescriptor.GetConverter(GetType(Double)).ConvertFrom(context, culture, s))
    26.             If (num3 > 1) Then
    27.                 num3 = (num3 / 100)
    28.             End If
    29.         Catch exception As FormatException
    30.             Throw New FormatException(SR.GetString("InvalidBoundArgument", New Object() {"Opacity", s, "0%", "100%"}), exception)
    31.         End Try
    32.         If ((num3 < 0) OrElse (num3 > 1)) Then
    33.             Throw New FormatException(SR.GetString("InvalidBoundArgument", New Object() {"Opacity", s, "0%", "100%"}))
    34.         End If
    35.         Return num3
    36.     End Function
    37.  
    38.     Public Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, ByVal culture As CultureInfo, ByVal value As Object, ByVal destinationType As Type) As Object
    39.         If (destinationType Is Nothing) Then
    40.             Throw New ArgumentNullException("destinationType")
    41.         End If
    42.         If (destinationType Is GetType(String)) Then
    43.             Dim num As Double = CDbl(value)
    44.             Dim num2 As Integer = CInt((num * 100))
    45.             Return (num2.ToString(CultureInfo.CurrentCulture) & "%")
    46.         End If
    47.         Return MyBase.ConvertTo(context, culture, value, destinationType)
    48.     End Function
    49.  
    50. End Class
    And this is the property, I just commented out some validations for simplicity.
    vb Code:
    1. ''' <summary>
    2.     ''' Gets or sets the size of the center-point that is directly proportional to the circumference of the clock.
    3.     ''' </summary>
    4.     <TypeConverter(GetType(PercentageConverter)), DefaultValue(0.03R), _
    5.     Bindable(True), Category("Layout"), Description( _
    6.     "Indicates the size of the center-point that is directly proportional to the circumference of the clock.")> _
    7.     Public Property CenterPointSize() As Double
    8.         '<DebuggerHidden()> _
    9.         Get
    10.             Return Me._centerPointRatio
    11.         End Get
    12.         '<DebuggerHidden()> _
    13.         Set(ByVal value As Double)
    14.             If Not Me._centerPointRatio.Equals(value) Then
    15.                 Me._centerPointRatio = value
    16.                 'If value < 0 Or value > 1 Then
    17.                 '    Throw New Exception("The value should be in the range of 0 to 100.")
    18.                 'Else
    19.                 '    Me._centerPointRatio = value
    20.                 '    Me.SetCenterPointPath()
    21.                 '    Me.ClockPanel.Invalidate()
    22.                 '    Me.ClockPanel.Update()
    23.                 'End If
    24.             End If
    25.         End Set
    26.     End Property

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

    Re: TypeConverter?

    I dont think that you need to go to all that trouble of using the reflector as I did custom formatting in an expandable property in 2003 just with a class or two. There is also a GetProperties overrides that should help. It should just be a matter of overriding a few functions and returning the proper valid format of the string?
    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
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    Yes Rob that is what I am doing, I just wanted to see how the .Net OpacityConverter class is implementing. The problem is that when I debug the UserControl the property is blacked out (unabled) but if I reference the UserControl in some windows application project I can see the property with its value formatted.
    I don’t know why it doesn’t work when I debug the UserControl but if I use OpacityConverter class it works perfect.

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

    Re: TypeConverter?

    Well it goes black when there is a bug or incorrect function calls for the property. Sometimes it can even crash your VS IDE when you click into a custom property when there is a bug with it. I know this first hand

    If it works with the OPC class then its easier to complete your project but I will try adding a % property to one of my demo UCs I made for a member.
    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

  13. #13

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    I used the OpacityConverter class for that property but the odd thing is that it throws “Opacity should be between 0% to 100%” message where my property has nothing to do with opacity if incorect value is entered. Can you take a look on my code and see what is wrong in there. The code I have is the exact copy of OpacityConverter class in .Net but for some reason it doesn’t work correctly. It might be that I should add some attribute to the class but I am not sure. And yes the property is blacked out if I debug the UserControl and if I clicked on it I get an exception “Object reference not set to an instance of an object.”
    Attached Images Attached Images  

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

    Re: TypeConverter?

    It shouldnt be blacking out all your properties unless they are all using the % formatted editor.

    Ps, dont you just love the UC Test Container?
    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
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: TypeConverter?

    I dont have the "System.Web.UI.MobileControls.Adapters" and I added a reference to the System.Web dll. Which is 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

  16. #16

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    I know I was talking about one property but actually all this blacked out properties should contain percentages of values.

    “Ps, dont you just love the UC Test Container?” I love it when it is not a pain etc

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

    Re: TypeConverter?

    Nevermine, I got 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

  18. #18

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    Quote Originally Posted by RobDog888
    I dont have the "System.Web.UI.MobileControls.Adapters" and I added a reference to the System.Web dll. Which is it?
    Add reference to "System.Web.Mobile"

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

    Re: TypeConverter?

    Ok you must have something going on in your project thats different because I used your code and it works fine. I have it in a project and not the test container.
    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

  20. #20

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    Yes Rob it works in a project if I reference the UserControl in that project but it doesn’t work in the test container. Also there is a small problem if I use it in some project, that is that if I enter incorrect value it shows an error box but if I click the details button the message is different than what I have in the class.

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

    Re: TypeConverter?

    Oh ok, now I see that its simptomatic in the testcontainer only.

    This is the error I got.

    "An unhandled exception of type 'System.NullReferenceException' occurred in mscorlib.dll

    Additional information: Object reference not set to an instance of an object."

    I bet it may just be as simple as a bug witht he testcontainer utility.
    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

  22. #22

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    It could be but if you use OpacityConverter it works perfect! Why this should be different? The code of the class is the same as of OpacityConverter class.

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

    Re: TypeConverter?

    The OpacityConverter probably has all the functions implemented that are required. You may need more overrides as the CanConvertTo function should be used as it is just as much needed as the CanConvertFrom and ConvertFrom functions.

    Also available:
    GetCreateInstanceSupported, CreateInstance, GetProperties, GetPropertiesSupported
    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

  24. #24

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    It might be true but when I check the OpacityClass in .Net Reflector it shows only these functions (see the image). could it be that the class is in the UserControl library?
    Attached Images Attached Images  

  25. #25

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: TypeConverter?

    Rob there is good news. I just created Class library project and copied the class in there and built it then referenced it in the UserControl project and it fixed it. I guess the problem was that I was using the class in the UserControl project where it should be outside. I don’t now why but it works! Thanks for patience and help also thanks goes to Jmc too. You guys are great !!! And sorry that I can’t give you guys reps for some reason it doesn’t allow me to do (I guess you are special ).

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

    Re: [RESOLVED] TypeConverter?

    I have mine outside the UC base file in a separate file but it seems like placing it in its own dll forces it to create an instance or something that the test container doesnt do.
    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

  27. #27

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [RESOLVED] TypeConverter?

    Quote Originally Posted by RobDog888
    I have mine outside the UC base file in a separate file but it seems like placing it in its own dll forces it to create an instance or something that the test container doesnt do.
    Yes I guess that is true.

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

    Re: [RESOLVED] TypeConverter?

    But I assume you are only going to keep it this way for debugging and testing as it would require an extra file to deploy with your control.
    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
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [RESOLVED] TypeConverter?

    Now I have another problem with validation. When I enter let say invalid value of 200 it throws an exception different message. I just left what the OpacityConverter class has in it but the message if different as you can see in the image.
    Attached Images Attached Images  

  30. #30

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [RESOLVED] TypeConverter?

    Quote Originally Posted by RobDog888
    But I assume you are only going to keep it this way for debugging and testing as it would require an extra file to deploy with your control.
    Yes I guess I should have the class in my UserControl project in the control’s final realize. I don’t want to have another dll file for this control. But I need to have this new problem (validation) fixed.

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

    Re: [RESOLVED] TypeConverter?

    Well other then a message that wont mean much to a user the property is kind of working

    When done in the project instead I get this error:
    Value cannot be null.
    Parameter name: format

    Where is "format" argument coming from? I would assume its something behind the scenes with FormatException.
    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

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

    Re: [RESOLVED] TypeConverter?

    The correct message should be ...

    Value of '200' is not valid for 'Opacity'. 'Opacity' should be between 0% and 100%.

    Also, (Edit) you should change the property name in the formatexception to reflect your property and not Opacity.

    Code:
    Throw New FormatException(SR.GetString("InvalidBoundArgument", New Object() {"CenterPoint", s, "0%", "100%"}))
    Last edited by RobDog888; Aug 27th, 2007 at 01:53 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

  33. #33

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [RESOLVED] TypeConverter?

    Quote Originally Posted by RobDog888
    Well other then a message that wont mean much to a user the property is kind of working

    When done in the project instead I get this error:
    Value cannot be null.
    Parameter name: format

    Where is "format" argument coming from? I would assume its something behind the scenes with FormatException.
    It might be that it throws another exception on that line I am not sure. And I don’t know where the “format” argument comes from but the problem should be in here:
    SR.GetString("InvalidBoundArgument", New Object() {"Opacity", s, "0%", "100%"}

  34. #34

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [RESOLVED] TypeConverter?

    Yes as I was guessing it is that line. It throws another exception if I do this:
    vb Code:
    1. Dim t As String = SR.GetString("InvalidBoundArgument", New Object() {"Opacity", s, "0%", "100%"})
    I need to take a look what is happening in here.

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

    Re: [RESOLVED] TypeConverter?

    Im assuming its coming from "s" since its supossed to contain the value.
    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

  36. #36

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [RESOLVED] TypeConverter?

    “s” has a value 200 at the error time so it is not null. I also checked the object array and it contains all the four arguments so this not spouse to be the problem. But I am not sure about the “InvalidBoundArgument” which spouse to be a system string name that my system is missing or maybe I can’t have “System.Web.UI.MobileControls.Adapters” in user control. I am going to pass on this one and just set the message of the exception with out using SR.
    Now the control works as it should. One thing that I still will look is to figure out why the properties are blacked out in the test container. I think the reason is that the class doesn’t generate an instance when it is declared as attribute, but there should be some attribute to apply to the class that may fix this problem. Anyways thank you so much Rob for all the help.

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

    Re: [RESOLVED] TypeConverter?

    No prob but I dont think I was able to help too much.

    I still think that when you are doing custom formatting of a property you need to use all four overrides: CanConvertTo, CanConvertFrom, ConvertFrom and ConvertTo.
    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

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