Reverse select a textbox

Posted on 2002-04-14
Last Modified: 2012-06-22

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)
Question by:dhwanilshah
  • 3
  • 2
  • 2
  • +5

Accepted Solution

Bahnass earned 100 total points
ID: 6939956
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!!

LVL 44

Expert Comment

ID: 6939961
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?

Expert Comment

ID: 6939987
one way....

Private Sub Text1_GotFocus()
Text1.SelStart = Len(Text1)
SendKeys "+{HOME}"
End Sub
LVL 45

Expert Comment

ID: 6940010
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.

Expert Comment

ID: 6940296
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.

LVL 22

Expert Comment

ID: 6943028
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.
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

LVL 45

Expert Comment

ID: 6943471
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.
LVL 49

Expert Comment

ID: 7654057
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
LVL 45

Expert Comment

ID: 7655263

I disagree with your recommendation.  Bahnass mentioned the righttoleft textbox property before Arthur_Wood (by four minutes).

Expert Comment

ID: 7655604
Thank aikimark
    any How My comment was to help asker who is not there even to say thanks!!

Thanks all EE's    
LVL 49

Expert Comment

ID: 7659767
Thanks for the input.  I'm changing my recommendation to:

  Accept Bahnass's comment(s) as an answer.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 7755045
per recommendation

Community Support Moderator @Experts Exchange

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now