Hiding inherited members

  • Thread starter Thread starter Troy Hilbert
  • Start date Start date
T

Troy Hilbert

I've created a class derived from NativeWindow. The public methods are
visible to consumers of my class and I don't wish them to be. How does one
hide those members?

Best
 
I was actually going to ask the same question. I'll give
you an example though.

If you look at the TrackBar control, there is no Text
property because there is no text rendered on the
control. The TrackBar inherits from the Control class,
which does have a Text property.

From what I understand, using the keyword new is supposed
to allow you to replace an inherited function with your
own. This doesn't work if you change the scope.

If I remember correctly, changing the scope does work in
VB with the Shadows keyword. I would assume that C#
would have some way to do it.
 
Mike M said:
I was actually going to ask the same question. I'll give
you an example though.

If you look at the TrackBar control, there is no Text
property because there is no text rendered on the
control.

But TrackBar *does* have a Text property. I'm not sure why it's not
document, but it *does* exist:

using System;
using System.Windows.Forms;

public class Test
{
static void Main()
{
TrackBar tb = new TrackBar();
tb.Text="hello";
}
}

compiles fine.
 
Then it must be hidden. It doesn't show up in the
intelliSense, which is good enough to avoid confusion.
The BrowsableAttribute just makes it so that it doesn't
show up in the property browser. I was wondering if the
ObsoleteAttribute might do it, but I it doesn't look like
it.
 
Mike M said:
Then it must be hidden. It doesn't show up in the
intelliSense, which is good enough to avoid confusion.
The BrowsableAttribute just makes it so that it doesn't
show up in the property browser. I was wondering if the
ObsoleteAttribute might do it, but I it doesn't look like
it.

I believe you're looking for EditorBrowsableAttribute.
 
Awesome. Thanks. You wouldn't happen to know where I
can find a nice, neat list of ALL the attributes, would
you? I found one in help, but either I'm blind or it
wasn't in the list.
 
Mike M said:
Awesome. Thanks. You wouldn't happen to know where I
can find a nice, neat list of ALL the attributes, would
you? I found one in help, but either I'm blind or it
wasn't in the list.

If you look up System.Attribute in MSDN and then expand "Derived
Classes" you'll get the immediately derived ones. It's in that list -
but it's a pretty big list!
 
Thanks, I was leaning in that direction after spelunking around MSDN. Man
I've got much to learn about object oriented design principles. Have any
recomendations for neophytes?
 
Troy Hilbert said:
Thanks, I was leaning in that direction after spelunking around MSDN. Man
I've got much to learn about object oriented design principles. Have any
recomendations for neophytes?

Write lots of code, work out what's unpleasant about it, and learn from
that. I dare say there are plenty of books that would help out (the
Gang of Four "Design Patterns" book, for instance) but experience is
the best teacher. There's nothing like doing it wrong to teach you to
do it right :)
 
Back
Top