PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2008 [RESOLVED] From String?-VBForums
Results 1 to 6 of 6

Thread: [RESOLVED] From String?

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,347

    Resolved [RESOLVED] From String?

    Just wondering how to create my own custom property that is an object but that allows a string to be passed in to the property grid to configure it...

    For example, with a font type property you can type "Microsoft Sans Serif, 18pt" into the property grid and it will create the appropriate font structure and fill it.

    Thanks in advance
    Kris

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: From String?

    here's an example of expandable properties:

    http://code.msdn.microsoft.com/count...ntrol-2da92ac3

  3. #3

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,347

    Re: From String?

    I know how to create expandable properties ... And I don't want this property in question to be expandable ... I want to be able to put in something as a string ... and it creates an object based on that string... color for eg is not expandable and you can put text into it and it converts it to the corresponding filled structure.

    Thanks
    Kris

  4. #4
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: From String?

    Does the object support creating with a string? Does it have a constructor that accepts a string? If not then you you will need to code that yourself and only you know what rules you would be inventing.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,145

    Re: From String?

    here's how:

    vb Code:
    1. Imports System.ComponentModel
    2.  
    3. Public Class UserControl1
    4.  
    5.     Private _color As Color
    6.     <TypeConverter(GetType(colorConverter))> _
    7.     Public Property Color() As Color
    8.         Get
    9.             Return _color
    10.         End Get
    11.         Set(ByVal value As Color)
    12.             _color = value
    13.         End Set
    14.     End Property
    15.  
    16. End Class

    uses a typeconverter class:

    vb Code:
    1. Imports System.ComponentModel
    2.  
    3. Public Class colorConverter
    4.     Inherits TypeConverter
    5.  
    6.     Public Overrides Function CanConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal sourceType As System.Type) As Boolean
    7.         Return sourceType Is GetType(String)
    8.     End Function
    9.  
    10.     Public Overrides Function ConvertFrom(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal culture As System.Globalization.CultureInfo, ByVal value As Object) As Object
    11.         If TypeOf value Is String Then
    12.             Return Color.FromName(value.ToString)
    13.         End If
    14.         Return MyBase.ConvertFrom(context, culture, value)
    15.     End Function
    16.  
    17.     Public Overrides Function CanConvertTo(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal destinationType As System.Type) As Boolean
    18.         Return destinationType Is GetType(Color)
    19.     End Function
    20.  
    21.     Public 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
    22.         If TypeOf value Is Color Then
    23.             Return DirectCast(value, Color).Name
    24.         End If
    25.         Return MyBase.ConvertTo(context, culture, value, destinationType)
    26.     End Function
    27.  
    28. End Class

  6. #6

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,347

    Re: From String?

    Thanks ... just what i needed

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width