Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / September 2006

Tip: Looking for answers? Try searching our database.

Exposing protected properties

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Al Christoph - 14 Sep 2006 16:06 GMT
I need to associate text with a toolstripseparator. The underlying class
toolstripitem has a text property which presumably toolstripseparator manages
to hide.

I want to code something like
Public Class ToolStripSeparatorEX
 Inherits ToolStripSeparator
 Public Property Text ' exposes Text
end class

I know how to do this in Delphi where it is trivial:-

QUESTION: How do it do it in VB 2005?

Incidentally, to microsoft lurkers once again I've had to post a question
because of the inadequacy of the VB help and my refusal to buy a $50 book.
There is a nice discussion of protection, etc but i did not find an example.
Signature

Regards,
Al Christoph
Senior Consultant
Three Bears Software, LLC
just right software @ just right prices @ 3bears.biz
Microsoft Certified Partner (ISV)
Coming soon: Windows Mail for Vista.

Kevin Spencer - 14 Sep 2006 19:15 GMT
Hi Al,

The underlying class in this case is System.Windows.Forms.Control, and the
reason that it is hidden is that it has no purpose in the
ToolsStirpSeparator class. Even if you were to expose it (which you could),
it wouldn't do what you expect it to, because it wasn't designed with a Text
property in mind.

Now, if you want to add a Text property, you can certainly do so, but it
isn't simply a matter of exposing the underlying property. You would have to
implement whatever manifestation of that property you desire in the Control,
perhaps by overriding the OnPaint method.

There are several ways to implement this property. First, and perhaps the
best/easiest, is to create a property and call it something other than
"Text." The reason why it's the best way is that your implementation of the
Control will not correspond to either the ToolsStirpSeparator class or the
Control class, but as it is documented in those classes, it could be
confusing. It is easiest because it doesn't involve dealing with the
underlying property. But that is not a major difference.

OTOH, if you want to implement the property as "Text," use the "new"
modifier. The "new" modifer hides the underlying property with the new one.
This, of course, makes the underlying property invisible to the world, but
it already was, so there's no loss involved. Example:

new public string Text { get { return _SomeString; } set { _SomeString =
value; } }

Signature

HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

What You Seek Is What You Get.

>I need to associate text with a toolstripseparator. The underlying class
> toolstripitem has a text property which presumably toolstripseparator
[quoted text clipped - 15 lines]
> There is a nice discussion of protection, etc but i did not find an
> example.
Al Christoph - 14 Sep 2006 19:47 GMT
Thanks for your response. You have introduced me to the new syntax, which is
what I was looking for. Unfortunately the syntax was for the wrong language.

QUESTION: How do you do this in VB?

Actually there are several very good reasons to associate the notion of Text
with a toolstripseparator. First and foremost, it makes writing the classic
customize dialog much easier. It gives you friendly text to put in the list
of things to hide or make visible. It also has consequences for the way my
help system works.

Text doesn't always mean display this on the control. Sometimes it can mean
offer this in places other than on the control where normal controls might
provide their Text property. One could play games with Tags to get similar
behavior but that complicates coding, and i like to reserve Tag for
situations where I can find no other solution or where a really elegant
solution depends on having a value in Tag.

Turns out that the way to do this is in your load code simply put
toolstripseparator1.text = "Separator 1"
etc.

.text doesn't appear in the drop down list of properties but it quick
capitalizes itself, and compiles just fine.

QUESTION: Is this expected behavior that will be supported for the
foreseeable future.

Regards,
Al Christoph
Senior Consultant
Three Bears Software, LLC
just right software @ just right prices @ 3bears.biz
Microsoft Certified Partner (ISV)
Coming soon: Windows Mail for Vista.

> Hi Al,
>
[quoted text clipped - 44 lines]
> > There is a nice discussion of protection, etc but i did not find an
> > example.
Kevin Spencer - 15 Sep 2006 14:14 GMT
See http://www.codeproject.com/useritems/OSH.asp

Signature

HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

What You Seek Is What You Get.

> Thanks for your response. You have introduced me to the new syntax, which
> is
[quoted text clipped - 97 lines]
>> > There is a nice discussion of protection, etc but i did not find an
>> > example.
Al Christoph - 15 Sep 2006 14:31 GMT
so to sum things up i'd need to do something like

...
  private mText as string
...
  public overrides propert Text() as string
     get
       return me.mText
...

In otherwords i have to provide my own variable to hold text because the
separator hides his value completely.

Oh yes, and if I want to use this in the IDE properties window I'd better
throw in some attributes.

Did i get it right this time?

Regards,
Al Christoph
Senior Consultant
Three Bears Software, LLC
just right software @ just right prices @ 3bears.biz
Microsoft Certified Partner (ISV)
Coming soon: Windows Mail for Vista.

> See http://www.codeproject.com/useritems/OSH.asp
>
[quoted text clipped - 99 lines]
> >> > There is a nice discussion of protection, etc but i did not find an
> >> > example.
Kevin Spencer - 15 Sep 2006 17:48 GMT
> Did i get it right this time?

Sorry, no. The article explains how to "Shadow" (VB) or "Hide" (C#)
properties in the base class. The code you posted uses "Overrides." I would
suggest re-reading it more carefully.

Signature

HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

What You Seek Is What You Get.

> so to sum things up i'd need to do something like
>
[quoted text clipped - 137 lines]
>> >> > There is a nice discussion of protection, etc but i did not find an
>> >> > example.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.