|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to set the TextBox digital only?Hi, men.
It's just a small problem. On previous VB, I can reset the keycode in the KeyDown or KeyUp event. But in VB.NET, The property of parameter "e" is readonly. How can I have a TextBox just only could be imputed digital. Without any letter. Thx There should be a better way to do this, but since I haven't looked I can
tell you about two ways that can work for you. 1. Use SendKeys with an Ignore flag I expect you are trying to change the keys inputted to some other value. Well when the user presses a key, set a Flag like IgnoreKey and then use sendkeys to use the corrected input to the textbox, only this time IgnoreKey will not process the keystroke and pass it as-is to the textbox. Then you can set IgnoreKey back to false. Whew... I hope you got what I tried to explain. 2. Modify the SelText property directly. Modifying the Text property is one memory intensive momma, so use the seltext property instead... Put some code like this in your keydown event. myTextbox.Seltext = mykeychar hmm.... Personally I really loved it when we could simply modify the KeyCode, I built a nice little app which sold a few thousand copies using just that functionality. :) Regards Cyril Gupta "Steven.Xu" <Steve***@discussions.microsoft.com> wrote in message Digits (0-9) and no leters (a-z) ?news:FC2B4C9C-8B27-4C22-A0BC-8E1D306DAF7B@microsoft.com... > It's just a small problem. On previous VB, I can reset the keycode in the > KeyDown or KeyUp event. But in VB.NET, The property of parameter "e" is > readonly. How can I have a TextBox just only could be imputed digital. > Without any letter. Masked Edit Control ? This is definitely an easier way to do it... I misunderstood your question a
bit. I didn't quite understand what you meant by digital input and thought you needed added functionality like changing the keystroke values. Definitely recommend the Masked Edit Control. It's included in VS2005. Regards Cyril Gupta "Steven.Xu" <Steve***@discussions.microsoft.com> schrieb: \\\> It's just a small problem. On previous VB, I can reset the keycode in the > KeyDown or KeyUp event. But in VB.NET, The property of parameter "e" is > readonly. How can I have a TextBox just only could be imputed digital. Imports System.ComponentModel.Component Imports System.Text.RegularExpressions .. .. .. Private Sub TextBox1_Validating( _ ByVal sender As Object, _ ByVal e As CancelEventArgs _ ) Handles TextBox1.Validating Dim SourceControl As TextBox = DirectCast(sender, TextBox) Dim ErrorText As String If Not Regex.IsMatch(SourceControl.Text, "^\d*$") Then ErrorText = "Value must consist of decimal digits." End If Me.ErrorProvider1.SetError( _ SourceControl, _ ErrorText _ ) End Sub /// -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
How to Exit an application properly on Error
[VB.NET express 2005] - Regular expressions Sharing source code between Vs2003 and Vs2005 IDE How to send an Email in VB.NET help urgent Wall Charts 2005 No Setup Project in 2005 Express Edition? Keep form on top of everything - even other apps ? Namespace not available... Deleting all forms in collection |
|||||||||||||||||||||||