473,809 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trapping the location of a keypress inside the existing string in a custom textbox

I'm building a custom textbox for numbers only (actually two of them - one
for integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current
string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all when
the string length is zero. However, if the user enters '345' and now wants
to change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event and
in what manner can I solve this?

Thanks for any help.

Bernie Yaeger
Nov 20 '05 #1
4 1168
You should be able to use textbox1.select ionstart to figure out where the
cursor is when the user hits a key...

Josh Moody
VSU Team

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
From: "Bernie Yaeger" <be*****@cherwe llinc.com>
Subject: trapping the location of a keypress inside the existing string in a custom textboxDate: Fri, 9 Jan 2004 16:04:43 -0500
Lines: 15
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <u2************ **@tk2msftngp13 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: ool-18b80c4e.dyn.op tonline.net 24.184.12.78
Path: cpmsftngxa07.ph x.gbl!cpmsftngx a06.phx.gbl!cpm sftngxa09.phx.g bl!TK2MSFTNGP08 .
phx.gbl!tk2msft ngp13.phx.gblXref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:171628
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

I'm building a custom textbox for numbers only (actually two of them - one
for integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current
string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all when
the string length is zero. However, if the user enters '345' and now wants
to change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event and
in what manner can I solve this?

Thanks for any help.

Bernie Yaeger


Nov 20 '05 #2
Bernie:

What about a Regex on key down, or simply trapping what's being pressed.
Combine the Ascii representation and append it to the current text. If that
new value will make it not be a number any more, than just eat the keypress.
With a regex (a really simple one would be \d*) you could do some pretty
complex validation.

HTH

Bill
"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:u2******** ******@tk2msftn gp13.phx.gbl...
I'm building a custom textbox for numbers only (actually two of them - one
for integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current
string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all when
the string length is zero. However, if the user enters '345' and now wants to change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event and
in what manner can I solve this?

Thanks for any help.

Bernie Yaeger

Nov 20 '05 #3
Hi BIll,

Both your idea and Josh's worked fine - tx!

Bernie

"William Ryan" <do********@nos pam.comcast.net > wrote in message
news:er******** ******@TK2MSFTN GP12.phx.gbl...
Bernie:

What about a Regex on key down, or simply trapping what's being pressed.
Combine the Ascii representation and append it to the current text. If that new value will make it not be a number any more, than just eat the keypress. With a regex (a really simple one would be \d*) you could do some pretty
complex validation.

HTH

Bill
"Bernie Yaeger" <be*****@cherwe llinc.com> wrote in message
news:u2******** ******@tk2msftn gp13.phx.gbl...
I'm building a custom textbox for numbers only (actually two of them - one for integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all when the string length is zero. However, if the user enters '345' and now

wants
to change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event and in what manner can I solve this?

Thanks for any help.

Bernie Yaeger


Nov 20 '05 #4
Hi Josh,

Both your idea and Bill Ryan's worked fine - tx!

Bernie

"Josh Moody [MSFT]" <Jo********@onl ine.microsoft.c om> wrote in message
news:bI******** ******@cpmsftng xa07.phx.gbl...
You should be able to use textbox1.select ionstart to figure out where the
cursor is when the user hits a key...

Josh Moody
VSU Team

--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
--------------------
From: "Bernie Yaeger" <be*****@cherwe llinc.com>
Subject: trapping the location of a keypress inside the existing string in
a custom textbox
Date: Fri, 9 Jan 2004 16:04:43 -0500
Lines: 15
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <u2************ **@tk2msftngp13 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: ool-18b80c4e.dyn.op tonline.net 24.184.12.78
Path:

cpmsftngxa07.ph x.gbl!cpmsftngx a06.phx.gbl!cpm sftngxa09.phx.g bl!TK2MSFTNGP08 . phx.gbl!tk2msft ngp13.phx.gbl
Xref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:171628
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb

I'm building a custom textbox for numbers only (actually two of them -

onefor integers and one that allows currency entries, but let's discuss the
integer only control). I'm having a problem knowing where in the current
string the user is trying to enter '-' (ascii 45). I have been able to
ensure it can't be entered twice, but I currenty only allow it at all whenthe string length is zero. However, if the user enters '345' and now wantsto change it to '-345' I don't allow it, because I don't know how to
determine if the entry is 34-5 or 3-45 or 345- or -345. In what event andin what manner can I solve this?

Thanks for any help.

Bernie Yaeger

Nov 20 '05 #5

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

Similar topics

13
3936
by: David Gray | last post by:
Greetings all, Quick newbie type question: I would like to be able to trap non-numerical data entered into a textbox via CTRL+C and/or Shift+Insert. I realise that this data can be validated using the TEXTn_validate event but I would like to stop the user before it gets that far.
6
4766
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
0
1752
by: Wiktor Zychla | last post by:
in my application I sometimes use KeyPress event. in the event handler I have to check the char the user is trying to type. in NTs everything is correct. however on W98 I've noticed that the character given in e.KeyChar (e is KeyPressEventArgs of course) is NOT correctly converted ToString() when I type polish specific letters! instead of the letter 'polish l' I get '3', instead of 'polish z' I get '?'
3
7383
by: Darryn Ross | last post by:
Hi, I am trying to catch the KeyPress event on my datagrid but it isn't working... i have also tried registering the handler with the event like this... dgGLBatch.KeyPress += new KeyPressEventHandler(dgGLBatch_KeyPress); but nothing changed. I was wondering wether a custom table and column style might have an effect on how this works???
0
4282
by: Steph. | last post by:
Hi, I have made a new custom TextBox control to enable ENTER and TAB keys to be trapped in the "KeyPress" and "KeyDown" Events. to do that I have overridden the "IsInputKey" property in my new control (derived from the TextBox control)(see code below). I can now manage the KeyPress/Down event raised by TAB and ENTER keys, but I have one problem : A sound (ding) is played by my computer every time I press the TAB or ENTER key in...
9
1379
by: Bernie Yaeger | last post by:
I'm trying to control the textbox keypress event to deal with a "." such that it disallows a second "." and no characters after 2 numbers beyond the "." (thus a currency value). I have no problem with the numeric characters, but I am using this to identify how many chars are after the ".", but it's not working: Dim pos As Integer pos = InStr(1, ratevar1.Text, ".")
2
1151
by: Peter Osawa | last post by:
Hi, I'm making a form with a statusbar. I added a custom control to statusbar (That control has only a textbox). I set KeyPreview to True on the form. Now I can monitor all keys pressed, but I want to know if it is possible to pass the parent form to my contol and process keypresses inside my contol, without coding my contols logic in the main form ?
7
2304
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using FindControl the only way to do it?
2
6278
by: Jason Huang | last post by:
Hi, How do I override a TextBox's KeyPress evnt? And how do we use it? Thanks for help. Jason
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.