Results 1 to 10 of 10

Thread: Overriding Custom UserControl Text Property

  1. #1

    Thread Starter
    Lively Member D.Viddy's Avatar
    Join Date
    May 2003
    Location
    Soldotna, Alaska
    Posts
    108

    Overriding Custom UserControl Text Property

    Why am I having so much doing this? I'm trying to override the default UserControl classes Text property, but I can't get it to show in design view properties. Here is my code, I'm sure someone has ran into this before.


    VB Code:
    1. Public Overrides Property Text() As String
    2.         Get
    3.             Text = Me.Text
    4.         End Get
    5.         Set(ByVal Value As String)
    6.             Me.Text = Value
    7.             Me.Invalidate()
    8.         End Set
    9.     End Property
    ~Dylan
    ~http://www.codebend.net
    ~The place for Internet Development help.

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    Is this any help?

    VB Code:
    1. <System.ComponentModel.Localizable(True)>Public Overrides Property Text() As String
    2.     'Your code.
    3. End Property
    This world is not my home. I'm just passing through.

  3. #3
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    Ive had a look and couldnt work it out either, hmmmm.
    If you just want to set the default value, you can do it by code (thats all it does anyway), in your form declaration (eg)

    VB Code:
    1. 'UserControl11
    2.         '
    3.         Me.UserControl11.Location = New System.Drawing.Point(184, 168)
    4.         Me.UserControl11.Name = "UserControl11"
    5.         Me.UserControl11.Size = New System.Drawing.Size(232, 120)
    6.         Me.UserControl11.TabIndex = 3
    7.         Me.UserControl11.Text = "This data"

    Id be interested in the result.

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780
    I forgot to add, you probly need to change your code to something like this, your not calling your base control.text property.

    VB Code:
    1. Public Overrides Property Text() As String
    2.         Get
    3.             Return MyBase.Text
    4.         End Get
    5.         Set(ByVal Value As String)
    6.             MyBase.Text = Value
    7.             Me.Invalidate()
    8.         End Set
    9.     End Property

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Why are you using Me.Invalidate() method , it means nothing if you're not doing any drawing stuff . I know this has nothing to do with the problem rather it's aside note .

  6. #6

    Thread Starter
    Lively Member D.Viddy's Avatar
    Join Date
    May 2003
    Location
    Soldotna, Alaska
    Posts
    108
    I am doing to Me.Invalidate because I am drawing my own custom button. I also draw my own text, so I really need to have the text property visible.
    ~Dylan
    ~http://www.codebend.net
    ~The place for Internet Development help.

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by D.Viddy
    I am doing to Me.Invalidate because I am drawing my own custom button. I also draw my own text, so I really need to have the text property visible.
    I know but it doesn't make sense here (to me at least since in this method I can't see any drawing stuff ) . Anyway , Did you try this ? (though this is what I do in all my custom controls and it works).

    VB Code:
    1. Private mText As String
    2.  
    3. Public Overrides Property Text() As String
    4.         Get
    5.             Return mText
    6.         End Get
    7.         Set(ByVal Value As String)
    8.             mText  = Value
    9.         End Set
    10.     End Property

  8. #8

    Thread Starter
    Lively Member D.Viddy's Avatar
    Join Date
    May 2003
    Location
    Soldotna, Alaska
    Posts
    108
    Uhhh yeah it does make sense, because if the user changes the text the control will need to be redrawn to reflect the changes.
    ~Dylan
    ~http://www.codebend.net
    ~The place for Internet Development help.

  9. #9

    Thread Starter
    Lively Member D.Viddy's Avatar
    Join Date
    May 2003
    Location
    Soldotna, Alaska
    Posts
    108
    None of this is working, hasn't anyone every made their own usercontrol and had the text property not show up in design time???
    ~Dylan
    ~http://www.codebend.net
    ~The place for Internet Development help.

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Did you try adding the Browsable attribute?
    VB Code:
    1. [b]<Browsable(True)> _[/b]
    2.     Public Overrides Property Text() As String
    3.         Get
    4.             Return MyBase.Text
    5.         End Get
    6.         Set(ByVal Value As String)
    7.             MyBase.Text = Value
    8.             Me.Invalidate()
    9.         End Set
    10.     End Property

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