mooman_fl Posted March 27, 2003 Posted March 27, 2003 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. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
Heiko Posted March 27, 2003 Posted March 27, 2003 Hm. I am using "Shadows" and it works fine. Quote .nerd
mooman_fl Posted March 27, 2003 Author Posted March 27, 2003 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. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
Heiko Posted March 27, 2003 Posted March 27, 2003 Did you step into the property setter? This seems very odd to me. Quote .nerd
mooman_fl Posted March 27, 2003 Author Posted March 27, 2003 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 Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
mooman_fl Posted March 27, 2003 Author Posted March 27, 2003 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. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
*Gurus* divil Posted March 27, 2003 *Gurus* Posted March 27, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
mooman_fl Posted March 27, 2003 Author Posted March 27, 2003 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? Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
*Gurus* divil Posted March 27, 2003 *Gurus* Posted March 27, 2003 <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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
mooman_fl Posted March 27, 2003 Author Posted March 27, 2003 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. Quote "Programmers are tools for converting caffeine into code." Madcow Inventions -- Software for the Sanity Challenged.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.