PC Review


Reply
Thread Tools Rate Thread

Caret in textbox

 
 
P
Guest
Posts: n/a
 
      12th Mar 2004
Is there a way to get the caret placed at the end of the text in a textbox
when it recieves focus. What I want to do is trap a certain key and insert a
charachter to a textbox and focus it. But the caret appears at the beginning
of the string. Not quite what I was looking for.

Advice?

<P>


 
Reply With Quote
 
 
 
 
Peter B
Guest
Posts: n/a
 
      12th Mar 2004
this.TextBox1.SelectionStart = this.TextBox1.Text.Length;

Should do it for you.

If you want to insert a character at the position of the caret this should
work:

int pos = TextBox1.SelectionStart;
TextBox1.Text = tBox.Text.Insert( pos, myChar );
TextBox1.SelectionStart = pos + 1;

/ Peter

--
This posting is provided "AS IS" with no warranties, and confers no rights.



"P" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a way to get the caret placed at the end of the text in a textbox
> when it recieves focus. What I want to do is trap a certain key and insert

a
> charachter to a textbox and focus it. But the caret appears at the

beginning
> of the string. Not quite what I was looking for.
>
> Advice?
>
> <P>
>
>



 
Reply With Quote
 
=?Utf-8?B?RGFuIEFyZGVsZWFu?=
Guest
Posts: n/a
 
      12th Mar 2004
You can place the carret wherever you want. To place it at the end use: this.textBox1.SelectionStart=this.textBox1.Text.Length; (you could write the following code in OnFocus event)
 
Reply With Quote
 
Pete Vickers [eMVP]
Guest
Posts: n/a
 
      12th Mar 2004
Hi,
try...
txtMyText.Focus
txtMyTest.SelectionStart = txtMyTest.TextLength

HTH

Pete

--
Pete Vickers
Microsoft Windows Embedded MVP
HP Business Partner
http://www.gui-innovations.com


"P" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a way to get the caret placed at the end of the text in a textbox
> when it recieves focus. What I want to do is trap a certain key and insert

a
> charachter to a textbox and focus it. But the caret appears at the

beginning
> of the string. Not quite what I was looking for.
>
> Advice?
>
> <P>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding caret of textbox Jared Microsoft Dot NET Framework Forms 1 2nd Feb 2006 02:52 PM
Get caret pos in TextBox =?Utf-8?B?ZGxncHJvYw==?= Microsoft Dot NET Framework Forms 1 13th Mar 2005 01:08 AM
Create box-like Caret for textbox Dayne Microsoft Dot NET 3 30th Nov 2004 07:01 PM
Caret position in textbox Emmet Cummings Microsoft C# .NET 2 6th Apr 2004 08:58 PM
caret in TextBox Coder Microsoft Dot NET Compact Framework 1 2nd Aug 2003 11:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:19 AM.