Keypress event
-
On keypress event i am disallow some of the some of the ascii value like this
if (((e.KeyChar >= 91 && e.KeyChar <= 96) || e.KeyChar == 123 || e.KeyChar == 124 || e.KeyChar == 125 || e.KeyChar == 42 || e.KeyChar == 33 || e.KeyChar == 35 || e.KeyChar == 38 || e.KeyChar == 40 || e.KeyChar == 39 || e.KeyChar == 34 || e.KeyChar == 41 || e.KeyChar == 44 || e.KeyChar == 64 || e.KeyChar == 61 || e.KeyChar == 59 || e.KeyChar == 58 || e.KeyChar == 63 || e.KeyChar == 60 || e.KeyChar == 62) != false) { e.Handled = true; }
Now hat i want when user press space bar (Ascii value 32) then it will print '~' (Ascii value 126) in place of Ascii 32 if user enter ABCD(SPACE)FGT THEN IT SHOULD PRINT ABCD~FGT -
On keypress event i am disallow some of the some of the ascii value like this
if (((e.KeyChar >= 91 && e.KeyChar <= 96) || e.KeyChar == 123 || e.KeyChar == 124 || e.KeyChar == 125 || e.KeyChar == 42 || e.KeyChar == 33 || e.KeyChar == 35 || e.KeyChar == 38 || e.KeyChar == 40 || e.KeyChar == 39 || e.KeyChar == 34 || e.KeyChar == 41 || e.KeyChar == 44 || e.KeyChar == 64 || e.KeyChar == 61 || e.KeyChar == 59 || e.KeyChar == 58 || e.KeyChar == 63 || e.KeyChar == 60 || e.KeyChar == 62) != false) { e.Handled = true; }
Now hat i want when user press space bar (Ascii value 32) then it will print '~' (Ascii value 126) in place of Ascii 32 if user enter ABCD(SPACE)FGT THEN IT SHOULD PRINT ABCD~FGTHi, You may use the following code: Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown If e.KeyCode = Keys.Space Then e.SuppressKeyPress = True Dim i As Integer i = Me.TextBox1.SelectionStart Me.TextBox1.Text = Me.TextBox1.Text + "~" Me.TextBox1.SelectionStart = i + 1 End If End Sub Hope this helps.
Vinay ComponentOne LLC. www.componentone.com
-
On keypress event i am disallow some of the some of the ascii value like this
if (((e.KeyChar >= 91 && e.KeyChar <= 96) || e.KeyChar == 123 || e.KeyChar == 124 || e.KeyChar == 125 || e.KeyChar == 42 || e.KeyChar == 33 || e.KeyChar == 35 || e.KeyChar == 38 || e.KeyChar == 40 || e.KeyChar == 39 || e.KeyChar == 34 || e.KeyChar == 41 || e.KeyChar == 44 || e.KeyChar == 64 || e.KeyChar == 61 || e.KeyChar == 59 || e.KeyChar == 58 || e.KeyChar == 63 || e.KeyChar == 60 || e.KeyChar == 62) != false) { e.Handled = true; }
Now hat i want when user press space bar (Ascii value 32) then it will print '~' (Ascii value 126) in place of Ascii 32 if user enter ABCD(SPACE)FGT THEN IT SHOULD PRINT ABCD~FGTWill this work?
if ( e.KeyChar == ' ' ) e.KeyChar = '~' ;
And the code you posted looks very difficult to maintain. -
Will this work?
if ( e.KeyChar == ' ' ) e.KeyChar = '~' ;
And the code you posted looks very difficult to maintain.Well no offense...but the code above is VB ;) ;P
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
-
Well no offense...but the code above is VB ;) ;P
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
No it isn't. Why do you say so? Or do you mean Vinay's response?
-
No it isn't. Why do you say so? Or do you mean Vinay's response?
second option:
PIEBALDconsult wrote:
Vinay's response
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.