Todd MacPherson
asked on
I need KeyPress code to limit textbox entry to 2 places of decimal
Hi
I am using vb.net 2005 compact framework. I have the following keypress code that limits values entered into a textbox to numeric entry and back space. I need to take it one step further and limit entry to 2 places of decimals.
Code thus far:
Private Sub txtStandArea_KeyPress(ByVa l sender As Object, ByVal e As System.Windows.Forms.KeyPr essEventAr gs) Handles txtStandArea.KeyPress
If Not Char.IsDigit(e.KeyChar) And Not e.KeyChar = "." And Not e.KeyChar = ChrW(8) Then
Beep()
e.Handled = True
End If
End Sub
I was trying to incorporate txtStandArea.Text.Length >= txtStandArea.Text.IndexOf( ".") + 2 into it but I just cant seem to get the proper way. Please help.
Thanks
PBLack
I am using vb.net 2005 compact framework. I have the following keypress code that limits values entered into a textbox to numeric entry and back space. I need to take it one step further and limit entry to 2 places of decimals.
Code thus far:
Private Sub txtStandArea_KeyPress(ByVa
If Not Char.IsDigit(e.KeyChar) And Not e.KeyChar = "." And Not e.KeyChar = ChrW(8) Then
Beep()
e.Handled = True
End If
End Sub
I was trying to incorporate txtStandArea.Text.Length >= txtStandArea.Text.IndexOf(
Thanks
PBLack
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it is not ctrl-c ctrl-v but if you click and hold the textbox, a menu will appear and let you copy and paste content
ASKER
emoreau
that is true if you only program that functionality into it.
PBLack
that is true if you only program that functionality into it.
PBLack
I thought that this feature was built-in in the textbox control!
ASKER
not that I can see
ASKER
Hi again
Since I think that I reached a solution that works outside of the expert suggestions I will divide the points up among those who took the time to share their ideas.
Their solutions are great 'food for thought' outside of the compact framework schema.
Regards,
PBLack
ps - experts-exchange should have a compact framework section!
Since I think that I reached a solution that works outside of the expert suggestions I will divide the points up among those who took the time to share their ideas.
Their solutions are great 'food for thought' outside of the compact framework schema.
Regards,
PBLack
ps - experts-exchange should have a compact framework section!
ASKER
The code I am using is working 100% as I wanted it to. Now if someone does know how to effect a copy-paste on this textbox I will have to change my ways as per your suggestions.
PBLack
Private Sub txtStandArea_KeyPress(ByVa
If Not Char.IsDigit(e.KeyChar) And Not e.KeyChar = "." And Not e.KeyChar = ChrW(8) Then
Beep()
e.Handled = True
Else
If e.KeyChar = "." And txtStandArea.Text.IndexOf(
Beep()
e.Handled = True
ElseIf e.KeyChar = "." Then
e.Handled = False
ElseIf Char.IsDigit(e.KeyChar) Then
If txtStandArea.Text.IndexOf(
If txtStandArea.Text.Length >= txtStandArea.Text.IndexOf(
Beep()
e.Handled = True
End If
End If
End If
End If
End Sub