473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Replace char in the OnKeyPress

Hello,

I think it is a easy question but I don't have any clue how to do it...Is it
possible to replace the char that a user type in a textbox with an other one
in the OnKeyPress methode? My textbox support 4 numbers types:
1-Integer
2-Decimal
3-Currency
4-Percent

I made a property with an Enum to support that. When the property NumberType
is set to 2, 3 or 4, I want the textbox to make no difference between the
"," and the "."

If the regional setting is set to "," and the user type "." I want my
textbox to change to the "," char. I validate this in the OnKeyPress methode
but I endup with the "." in the Textbox. I do something like this in the
OnKeyPress methode when NumberType is set to 2.

e = New
KeyPressEventArgs(convert.tochar(system.Globalizat ion.NumberFormatInfo.CurrentInfo.NumberDecimalSepa rator
))

I know that this is not the right solution because it's not working.

I need help

Thank you
Nov 21 '05 #1
2 3294
Marc,

You mean something quick and dirty made as this?

For others, this can be (sometimes) a problem in countries where a US
keyboard fulfils all the needs except the decimal comma

\\\
Private Sub textbox1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.Decimal OrElse e.KeyCode = Keys.OemPeriod Then
Dim pos As Integer = TextBox1.Text.Length - 1
TextBox1.Text = TextBox1.Text.Substring(0, pos) & Chr(44)
TextBox1.SelectionStart = TextBox1.Text.Length
TextBox1.SelectionLength = 1
End If
End Sub
///

I have beside the num keyboard as well taken the period, in my opinion it is
better when you keep that period on the normal keyboard the same and delete
that part from this code.

I hope this helps?

Cor

Nov 21 '05 #2
Hey! Thank you

It is exactly what I wanted. Simple and effective
Thank you again

"Cor Ligthert" <no************@planet.nl> a écrit dans le message de news:
ei**************@TK2MSFTNGP10.phx.gbl...
Marc,

You mean something quick and dirty made as this?

For others, this can be (sometimes) a problem in countries where a US
keyboard fulfils all the needs except the decimal comma

\\\
Private Sub textbox1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.Decimal OrElse e.KeyCode = Keys.OemPeriod Then
Dim pos As Integer = TextBox1.Text.Length - 1
TextBox1.Text = TextBox1.Text.Substring(0, pos) & Chr(44)
TextBox1.SelectionStart = TextBox1.Text.Length
TextBox1.SelectionLength = 1
End If
End Sub
///

I have beside the num keyboard as well taken the period, in my opinion it
is better when you keep that period on the normal keyboard the same and
delete that part from this code.

I hope this helps?

Cor

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: pembed2003 | last post by:
Hi all, I asked this question in the C group but no one seems to be interested in answering it. :-( Basically, I wrote a search and replace function so I can do: char source = "abcd?1234?x";...
13
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code...
5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
2
by: ~toki | last post by:
How can i take the control of the key events in Class2 ? This is the code snipped that i'd tried (after try some others): public class Main : System.Windows.Forms.Form { protected virtual...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
6
by: JackpipE | last post by:
Here is my replace query and I need to run this on every column in my table. Right now I manually enter the column name (_LANGUAGES_SPOKEN) but this is time consuming and would like to automate...
6
by: tonySAN | last post by:
Hi, I have the following code which works fine in IE but does not in Firefox: <html> <head> <title>space-plus</title> <script type="text/javascript"> <!-- function alpha(e) { ...
18
by: Umesh | last post by:
Do you have any answer to it? thx.
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.