I have my own control:
public class newControl : Control
{
}
There is a Text property, but there is not a TextAlign property. For example, I need this property similar to the TextAlign property of a Button, but I don’t want inherit it from a button class.
So can I inherit only TextAlign property? If yes, how?
Yes, you can just add it. The built in enumeration is called
ContentAlignment:What you do with this property is up to you now.
Note that I added some attributes for how the control is used in the
PropertyGrid. TheDefaultValueattribute does not set the value of the property, it just determines whether or not the property is displayed in bold or not.To display the text using your
TextAlignproperty, you would have to override theOnPaintmethod and draw it: