Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am wanting to add the Public property Text() to my usercontrol. It obviously can't be added as a regular property. When I try adding it the normal way I am given an error saying it Shadows an overridable method in a base class.

 

So I tried this:

 

Public Overrides Property Text() As String
   Get
       Return strHeaderText
   End Get
   Set(ByVal Value As String)
       strHeaderText = Value
       Header.Text = strHeaderText
   End Set
End Property

 

This seems to work fine when changing the property programmatically (i.e. It shows up in the intellisense list) but the property doesn't show up at designtime in the property list.

 

What am I doing wrong? Also a brief explanation as to why it is wrong will help me from making the same mistakes later.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted

Hmmm... just changed it to:

 

Public Shadows Property Text() As String
   Get
       Return strHeaderText
   End Get
   Set(ByVal Value As String)
       strHeaderText = Value
       Header.Text = strHeaderText
   End Set
End Property

 

All that seemed to do is break it. It still doesn't show at designtime in the IDE property list. It does still show in intellisense. However using it programmatically no longer changes the text at all.

 

Still needing help with this.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted
Maybe this will help better demonstrate the problem. I am trying to use the Text() property to change the text on the Header control. Header is just a normal label control. My project is attached below.

toolpanel.zip

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Posted

Nevermind. Thanks for trying to help. I figured it out. Shadowing the property works but I had to save everything, build the project, then close down and start a new project. Once the control was added to that project it would show up and everything worked.

 

For some reason this is another one of those things that just wouldn't show in the startup project I was using while making the control.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • *Gurus*
Posted
The reason is that all controls already have a Text property, you really don't have to make your own. What you have to do is override it and call back to the base class to set and get it, and use a Browsable(True) attribute on it to make it show in the property grid.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Once again divil thank you. That is a bit different that what I am doing at the moment and I have just noticed that what I have works off and on.

 

Using the example code I posted about could you give me an example of what you are talking about?

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

  • *Gurus*
Posted

<Browsable(True)> _
Public Overrides Property Text() As String
   Get
       Return MyBase.Text
   End Get
   Set(ByVal Value As String)
       MyBase.Text = Value
   End Set
End Property

 

Abolish your strHeaderText variable, and just use Me.Text instead. The Browsable attribute I used there is in System.ComponentModel.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
Thanks... I will give this a shot. I will have to modify it a bit though since what I am trying to do is set the text on a label on the control.

"Programmers are tools for converting caffeine into code."

 

Madcow Inventions -- Software for the Sanity Challenged.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...