selecting text in a textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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!
***************************
 
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
 
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/csharpsample/default.aspx
 
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top