• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

Reverse select a textbox

Hey,

I have a single line text box. I would like to select the text in the text box so that when that text box receives focus, the text would be selected from right to left instead of left to right. Left to right selection if provided by :

txtBox1.SelStart = 0
txtBox1.SelLength = Len(txtBox1.Text)
0
dhwanilshah
Asked:
dhwanilshah
  • 3
  • 2
  • 2
  • +5
1 Solution
 
BahnassCommented:
Sorry Don't understand U???
lines U wrote are selecting the hole textbox area (So no write or left)

no of char in text box is given by Len(txtBox1.Text)

if U want to select first 2 char
txtBox1.SelStart = 0
txtBox1.SelLength = 2

if U want last 2 char
txtBox1.SelStart = Len(txtBox1.Text)-2
txtBox1.SelLength = 2

textbox has righttoleft property to display contents in that order

Hope that helps!!!!!!    thaugh I don't understand Q!!

0
 
Arthur_WoodCommented:
in VB 6, you can change the RightToLeft property of the text box to TRUE, then text will be entered into the text box from Right To Left, (the default is Left to Right).  Is that what you are asking?
0
 
jbilCommented:
one way....

Private Sub Text1_GotFocus()
Text1.SelStart = Len(Text1)
SendKeys "+{HOME}"
End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aikimarkCommented:
What are you trying to accomplish with this?  If all the text is selected, what difference does it make if it is selected from left-to-right or right-to-left?

jbil seems to have workable solution.  In a production environment, I would look at using the SendMessage API instead of SendKeys if feasable.
0
 
Chandramouli kArchitectCommented:
I dont see any difference for a text selecting in what so ever order. btw, when a text is selected in a textbox, and if the text box loses the focus, the selection is also gone.

*****the text would be selected from right to left instead of left to right*****

What does it mean? could u Pls post some more info.

KCM
0
 
rspahitzCommented:
Just observing...
Try this experiment and you'll understand the question:

Click on [Start]|Run...

In the run combobox if you don't have something selected, enter Notepad, click OK, then repeat until something is selected.

Look carefully at the selected text and notice that the cursor is at the END of the selected text.  Press the left arrow key and notice that the cursor ends up to the left of the last character.

Now press the following key sequence: END, SHIFT+HOME

Notice that everything is highlighted, but the cursor is now blinking at the beginning.  Try cursor left again and notice that the cursor ends up at the beginning of the text.

Similarly, using shift-cursor will give different results.

--
Why do you need this?  Convenience for some things, but ultimately I'd say that since no other applications do it, there's a good chance that this convenience will simply confuse many users and may not be worth the effort.
0
 
aikimarkCommented:
Having your application automatically select the text is meant to be a convenience for the user to not have to delete text before typing completely new text.  

If the user wants to append new text, they must one of the following:
* press the End key
* press the right arrow key
* click to the right of the text with the mouse

If the user wants to prepend new text, they must one of the following:
* press the Home key
* click to the left of the text with the mouse
(Yes they can hold the left arrow key until the cursor reaches the start of the text, but the Home key is simpler and quicker.)

Without further information from you, we experts are at a loss to do anything other than advise you to avoid non-Windows-standard behavior.
0
 
DanRollinsCommented:
Hi dhwanilshah,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Arthur_Wood@devx's comment(s) as an answer.

dhwanilshah, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
aikimarkCommented:
DanRollins,

I disagree with your recommendation.  Bahnass mentioned the righttoleft textbox property before Arthur_Wood (by four minutes).
0
 
BahnassCommented:
Thank aikimark
    any How My comment was to help asker who is not there even to say thanks!!

Thanks all EE's    
0
 
DanRollinsCommented:
Thanks for the input.  I'm changing my recommendation to:

  Accept Bahnass's comment(s) as an answer.
==========
DanRollins -- EE database cleanup volunteer
0
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now