473,396 Members | 1,892 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,396 software developers and data experts.

selecting text in a textbox

Hi,
I need to write something so that when a textbox is entered (this is for a
touchscreen), all the text in that textbox is selected (highlighted) and new
keystrokes replace the old text. Help!
Thanks (again),
Melanie
Nov 17 '05 #1
4 3136
I am not sure which event to use in Windows Forms apps, but with a Web Kiosk
type app, you would use the OnFocus to select all text in the control.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"melanieab" wrote:
Hi,
I need to write something so that when a textbox is entered (this is for a
touchscreen), all the text in that textbox is selected (highlighted) and new
keystrokes replace the old text. Help!
Thanks (again),
Melanie

Nov 17 '05 #2
To highlight the contents of a TextBox, simply set it’s SelectionStart
property to 0, and SelectionLength to the length of the text within ala:

myTextBox.SelectionStart = 0;
myTextBox.SelectionLength = myTextBox.Text.Length;
myTextBox.Focus();

The Focus() ensures that the TextBox receives focus so that you can see the
selection. Or, if you have already set HideSelection to false, then you can
drop the call to Focus().

Brendan
"melanieab" wrote:
Hi,
I need to write something so that when a textbox is entered (this is for a
touchscreen), all the text in that textbox is selected (highlighted) and new
keystrokes replace the old text. Help!
Thanks (again),
Melanie

Nov 17 '05 #3
You need to use JavaScript for this unless you want to send the page back to
the server and then send the page back to the client again which is a drag
on performance and poor usability which I contend is perhaps the most
significant reason touchscreen applications have rarely been successful,
e.g. once a user tries to use the application and it runs like sh!t they
never use it again.

Go to the JavaScript FAQ [1] and you will learn how to get text in a textbox
selected and replaced. Only go back to the server if you have to. Be aware
of a methodology called AJAX [A(synchronous) JA(vascript( X(ml)] as it is a
methodology that allow the contents of a control such as a textbox to be
sent back to the sever and back again without needing to send the whole
page.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://developer.irt.org/
[2] http://ajax.schwarz-interactive.de/c...e/default.aspx


"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
Hi,
I need to write something so that when a textbox is entered (this is for a
touchscreen), all the text in that textbox is selected (highlighted) and
new
keystrokes replace the old text. Help!
Thanks (again),
Melanie

Nov 17 '05 #4
Hello,

Use textbox element's select() and focus() methods as in:

<input type=text name="txt">
<input type=button value="Select Text" onClick="txt.select();txt.focus();">

HTH

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
Hi,
I need to write something so that when a textbox is entered (this is for a
touchscreen), all the text in that textbox is selected (highlighted) and new
keystrokes replace the old text. Help!
Thanks (again),
Melanie
Nov 17 '05 #5

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

Similar topics

3
by: DOTNETGUY | last post by:
What i am doing is pretty simple. I am writing a simple control that you probably have seen on many websites. You have a phone number field ( 3 Textboxes ) if the size of the textbox text is = 3...
3
by: Harry Simpson | last post by:
I've got a server-side textbox that receives the focus when the page loads. It has the text "Refine your Search" in the textbox. Obviously the user needs to highlight the "Refine your Search"...
3
by: Strange Cat | last post by:
Hi everyone Is it possible to select the contents in an aspnet textbox? (Like the old textbox selectstart and so on properties) Thanx in advance
5
by: marfi95 | last post by:
I'm very confused. I'm trying to automatically select the text when my textbox gets the focus. This is typically when the user has clicked the mouse in the field. This is the code I have in...
4
by: rcoco | last post by:
I want to select one Row from a datagrid so I create a textBbox(txtname) and Button for the user to write the name in textBox and By the click of the button it select the corresponding row. But...
2
by: Abubakar | last post by:
Hi, In a normal Windows.Forms.TextBox control, I want to be able to select a text (ie highlight, this is by default possible) and than be able to drag that text through my mouse pointer to another...
2
by: JJ | last post by:
I have a textbox that is used to insert some html code. I want to highlight errors in the code, possibly by selecting the text. Is it possible to highlight/select areas of a textbox...
1
by: David C | last post by:
I see that the .Focus() method is new in .NET 2.0, which I think is handy. But is there a way to make text in a textbox selected when the focus is set in it? This would be equivalent to calling...
3
by: Shawn | last post by:
I'm trying to go through a large number of logically named textboxes using a loop and cannot figure out how short of explicitly referencing every single one.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.