Click here to Skip to main content
15,920,110 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

I create 1 application.In that have to take one textbox.when i type 1st character then its not get select.infact i don't want to selct it.after it when i type 2nd letter after 1st letter want to highlight it.i highlight it.then whane i type 3rd letterthen it alwys replace by 2nd position.I don't want like that.when i press right key then only i can add 3rd lette r in textbox.but evrytime press righ key.

So my main question is that how to set cursor position automatically after type any character? and also how to select/highlight this all characters except 1st one?
Posted
Comments
Zoltán Zörgő 1-Jun-12 9:09am    
WinForms, WebForms, WPF, Silverlight...?

For Windows.Forms use TextBox.Select(Int32, Int32)[^] method.
 
Share this answer
 
If you want to highlight part of the text in a TextBox rather than selecting it, you need a specialized textbox control.
You also might try this one: Fast Colored TextBox for Syntax Highlighting[^]
It is not easy to make your own textbox implementation, since it relays on low level api tools - but you can start from it's original code.
 
Share this answer
 
v2
In C#..
write the below line wherever is necessary
TextBOx1.Focus();
 
Share this answer
 
Hello,

In C#,windows application have to create my project.I tried above code.But,by using it i just select 2nd position character.when try to enter 3rd character it replace by 2nd position.
 
Share this answer
 
Comments
Zoltán Zörgő 2-Jun-12 4:24am    
1) This is not a solution, it is a comment!
2) You actually want to highlight, not to select? If it is selected, pressing a key will always overwrite the selected part. This is windows default behavior.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900