By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,884 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

NumericUpDown control

P: n/a
It is possible to format the numeric value of the NumericUpDown control

For example : display numbers in 2 digits, instead of 1 display 01, 0
-> 00 , 9 -> 09

Any idea

--
Ceci est une signature automatique de MesNews.
Site : http://www.mesnews.net

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Looks like the control only offers Hexadecimal, DecimalPlaces, and
ThousandsSeparator properties to control the format, not custom
formats.

You can probably subclass the control, add a Format property, and
override the UpdateEditText method to support a custom format like you
want.

However, since the ParseEditText property is not declared as
overridable, you can not add the logic needed to parse a totally
custom format--the format must be compatible with the default
Decimal.Parse() method.

If you do need an incompatible format, then I think the only option is
to create an entirely new NumericUpDown control that inherits
UpDownBase. It's a shame that so many of the windows controls methods
are not declared overridable--makes extending them difficult.

HTH,

Sam
On Thu, 23 Dec 2004 16:34:10 +0100, bnob <bn**@bluewin.ch> wrote:
It is possible to format the numeric value of the NumericUpDown control

For example : display numbers in 2 digits, instead of 1 display 01, 0
-> 00 , 9 -> 09

Any idea


Nov 21 '05 #2

P: n/a
Easy. Just Overrides Text property

Public Class myNumericUpDown
Inherits System.Windows.Forms.NumericUpDown

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container()
End Sub

#End Region

Public Overrides Property Text() As String
Get
Return MyBase.Text
End Get
Set(ByVal Value As String)
If Value.Length = 1 Then
MyBase.Text = "0" + Value
Else
MyBase.Text = Value
End If
End Set
End Property
End Class

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.