Imports System.Drawing
Imports System.Windows.Forms
Imports System.Web.UI
'
<ToolboxBitmap(GetType(TextBox))> _
Public Class SexyTextBox : Inherits TextBox
Public Enum TextBoxDisplayManager As Byte
TextCharacter = 0
TextNumber = 1
TextInteger = 2
End Enum
Public Enum TextBoxDisplayPrecisionScale As Byte
None = 0
One = 1
Two = 2
Tree = 3
Four = 4
End Enum
Public Enum TextBoxDisplayOnEnterMoveNext As Byte
Yes
No
End Enum
Public Enum TextBoxDisplayIsEnabledBinding As Byte
Yes
No
End Enum
Protected Overrides Sub OnValidating(ByVal e As System.ComponentModel.CancelEventArgs)
If Me._DisplayManager = TextBoxDisplayManager.TextNumber Then
Dim dblSubMybaseText As Double
If String.IsNullOrEmpty(MyBase.Text) OrElse Not IsNumeric(MyBase.Text) Then
dblSubMybaseText = 0
Else
dblSubMybaseText = CDbl(MyBase.Text)
End If
Select Case Me._DisplayPrecisionScale
Case TextBoxDisplayPrecisionScale.One
MyBase.Text = String.Format("{0:N1}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Two
MyBase.Text = String.Format("{0:N2}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Tree
MyBase.Text = String.Format("{0:N3}", dblSubMybaseText)
Case TextBoxDisplayPrecisionScale.Four
MyBase.Text = String.Format("{0:N4}", dblSubMybaseText)
Case Else
MyBase.Text = String.Format("{0:N0}", dblSubMybaseText)
End Select
End If
End Sub
End Class