How do I set specific properties for a subclass in C# .NET?

.net, c#

Solution

The base class already has those properties. Doing what you're doing should cause the compiler to complain (since you're hiding the base class member without using `new` to denote you want to hide it).

You don't need to make new properties - just set the base class defaults how you want in your constructor:

public class PermaToolTip : ToolTip
{
     public PermaToolTip()
     {
        // Define defaults differently now
        this.ShowAlways = true;
        this.IsBalloon = true;
        this.AutomaticDelay = 750;
        this.AutoPopDelay = 32767;
     }
}

This will cause your class to use the `ToolTip` properties, but with different default values.

Problem

First of all, let me just state that I'm new to .NET so I apologize in advance if my question is too naive or the answer too straightforward. I did some research and tested different things but I can't get it to work. What I'm trying to do: I have a lot of different tooltips in my form and I want them to have the same properties. For example: ``` mySampleTooltip.ShowAlways = true; mySampleTooltip.IsBalloon = true; mySampleTooltip.AutomaticDelay = 750; mySampleTooltip.AutoPopDelay = 32767; ``` Instead of doing that for every single tooltip and pasting the code 100 times, I thought that there may be a more elegant solution. My idea was to create a subclass of the class ToolTip which I called PermaToolTip and create objects from this specific class (is that the right approach by the way or maybe there is a better way?). My code looks like this: ``` public class PermaToolTip : ToolTip { private bool _ShowAlways; private bool _IsBalloon; private int _AutomaticDelay; private int _AutoPopDelay; // SET ShowAlways Property for subclass public bool ShowAlways { get { return _ShowAlways; } set { _ShowAlways = true; } } // SET IsBalloon Property for subclass public bool IsBalloon { get { return _IsBalloon; } set { _IsBalloon = true; } } // SET AutomaticDelay Property for subclass public int AutomaticDelay { get { return _AutomaticDelay; } set { _AutomaticDelay = 750; } } // SET AutoPopDelay Property for subclass public int AutoPopDelay { get { return _AutoPopDelay; } set { _AutoPopDelay = 32767; } } } ``` but it doesn't work. Specifically: 1) I get a green line below the property names and a warning that says: Warning: 'ResellerRatingsGUI.PermaToolTip.ShowAlways' hides inherited member 'System.Windows.Forms.ToolTip.ShowAlways'. Use the new keyword if hiding was intended. 2) I instantiate an object of the class PermaToolTip and it does not have the properties that I want it to have. Answer to comment: it's not user-defined controls. It's .NET controls. Any idea what I'm doing wrong?

Original source