Results 1 to 6 of 6

Thread: Custom Control Designer Questions

  1. #1
    instantmaker is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Aug 2009
    Posts
    4
    Reputation
    0

    Custom Control Designer Questions

    Hi all,

    I have a simple custom control with a button on it (composite control). Which I override the Text property so that in the property page I can set the "Text" property to reflect the text on the button. However, everytime when I recompile the control, the text on the button will go back to "button1". For example, if I dropped that custom control on a form and tried to change its Text property to some other text, like "Click Me". As soon as I recomplie the composite control itself, it will go back to "Button1". I suspect that it is because the default text on the button itself is "button1". My question is that if there is a way to keep the text?

    Any help would be appreicated. Thanks

  2. #2
    Robert_Zenz's Avatar
    Robert_Zenz is offline VB.NET Forum Idol
    .NET Framework
    .NET 2.0
    Join Date
    Jun 2008
    Location
    Vienna, Austria
    Posts
    503
    Reputation
    339
    Hello.

    Could you post the Property which you use to set the text?

    Best Regards,
    Bobby
    Don't give TypeCasting Errors a chance, turn ON Option Strict!

  3. #3
    instantmaker is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Aug 2009
    Posts
    4
    Reputation
    0
    Quote Originally Posted by Robert_Zenz View Post
    Hello.

    Could you post the Property which you use to set the text?

    Best Regards,
    Bobby
    The property looks like this


    Code:
    Public Property Shadows Text() As String
          Get
                Return Button1.Text
          End Get
          Set(ByVal value As String)
                Button1.Text = Value
          End Set
    End Property
    I don't have Visual Studio with me at the moment, but it should look close enough. Thanks for helping in advance.

  4. #4
    instantmaker is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Aug 2009
    Posts
    4
    Reputation
    0
    can anybody help with the problem??

    thanks

  5. #5
    newguy's Avatar
    newguy is offline VB.NET Forum Idol
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jun 2008
    Location
    Denver Co, USA
    Posts
    611
    Reputation
    250
    Try something like this:
    Code:
    <Browsable(True)> _
    Public Property ButtonText() As String
        Get
            Return button1.Text
        End Get
        Set(ByVal Value As String)
            button1.Text = Value
        End Set
    End Property
    The browsable attribute will show the property in the designer.
    Close Counts for Horseshoes, Handgranades, and Nuclear Missiles!

  6. #6
    instantmaker is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Aug 2009
    Posts
    4
    Reputation
    0
    Quote Originally Posted by newguy View Post
    Try something like this:
    Code:
    <Browsable(True)> _
    Public Property ButtonText() As String
        Get
            Return button1.Text
        End Get
        Set(ByVal Value As String)
            button1.Text = Value
        End Set
    End Property
    The browsable attribute will show the property in the designer.
    I did try that. Actually I found a solution how to keep the text after recompiling. what I did was to include <DesignerSerializationVisibility(DesignerSerializa tionVisibility.Visible)> on the property...that way it will keep the user settings. Also you are correct that I needed to include <Browsable(True)> _ to expose the property to the property window in the designer.

    Thanks

Tags for this Thread

Bookmarks

Posting Permissions

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