I’m wiriting a Numeric TextBox user control to filter non numeric digits. I want to set the TextAlign property default value to Right when I drop it to a Form, but I can´t manage to do it. I browsed the web and all I get is some form of overriding the property TextAlign, but nothing works. Any help will be appreciated. Thanks.
Public Class NumericTextBox
Inherits TextBox
<DefaultValueAttribute(HorizontalAlignment.Right)> _
Public Overloads Property TextAlign() As HorizontalAlignment
Get
Return MyBase.TextAlign
End Get
Set(ByVal value As HorizontalAlignment)
MyBase.TextAlign = value
End Set
End Property
From the documentation (in a big yellow box):
Therefore, you have to set the default value in the constructor of your inherited class. Moreover, you have to use Overrides instead of Overloads in the property.
There are lots of related questions on Stackoverflow: