0

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
DanielB
  • 117
  • 2
  • 9

1 Answers1

0

From the documentation (in a big yellow box):

A DefaultValueAttribute will not cause a member to be automatically initialized with the attribute's value. You must set the initial value in your code.

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:

Community
  • 1
  • 1
Andreas
  • 1,751
  • 2
  • 14
  • 25
  • Ok, it works adding the constructor. Overloads is right, if I declare the property as Overrides, an error is raised because TextBox is no Overridable. Thanks a lot. – DanielB Jul 27 '12 at 05:53