Format TextBox as number

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a MyTextBox class that inherits from TextBox. How do I make it
display the information as, say 0.00. Sometimes the value will be typed by
the user. Other times the value will be filled in when a User makes a
selection elsewhere.

I'd appreciate any help.

Art
 
Hi,

You might be better using a numericupdown control instead

Ken
--------------
Hi,

I have a MyTextBox class that inherits from TextBox. How do I make it
display the information as, say 0.00. Sometimes the value will be typed by
the user. Other times the value will be filled in when a User makes a
selection elsewhere.

I'd appreciate any help.

Art
 
Ken,

Thanks for the response, but unless there's more to the numericupdown I
don't think that will help. The specific numbers that will be entered will
be hourly rates for contractors. Possible values could be 65, 120, 190. The
text box will be an area to fill this in. However, if a contractor has a
"default" rate, then selecting that contractor from a ComboBox will
automatically put a number in the TextBox.

The rates will typically be multiples of 5. Will a numericupdown allow
that? Will it allow manual entry?

Thanks again,

Art
 
Since you've created a subclass from the textbox already, you can force
a format when you assign text to the box.

'---------- Overload the text assign value so that numeric / alpha
data may be formatted ---------
Overloads Property Text(ByVal FormatData As Boolean) As String
Get
Text = Me.Text
End Get
Set(ByVal Value As String)
Me.Text = Value
If FormatData Then FormatText()
End Set
End Property

You could also force a format of data when the textbox loses focus

Private Sub YourClass_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Leave
FormatText() ' Format per mask
End Sub

'--------- Format the string ---------
Public Sub FormatText()
If m_MaskValue = "" Or m_MaskValue = Nothing Then Exit Sub ' No
check
Me.Text = YourFormatRoutine(Me.Text, m_MaskValue)
End Sub
 
Shane,

Thanks very much. I was wondering about a recursive problem, but I see your
boolean argument fixes that. I assume that in the format area I would set it
to false.

Art
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top