Can I find the currently selected text on a form.

darbid

Registered User.
Local time
Today, 19:24
Joined
Jun 26, 2008
Messages
1,428
Hi guys

If a user highlights some text in a field and then clicks a button, in the button click event can I get the highlighted text as a string?

The highlighted text could be one word or the whole field.
The control in which text is highlighted is not know if could be any of them on the form.

regards

David
 
How about

Screen.ActiveControl.SelText
 
and what is the trick in using that.

when I click a button - the button is the active control??????
 
Sorry I guess it won't work the way I had envisioned it.
 
when I saw your answer I was thinking that my question was stupid. I was also really hopeing that your solution would work. oh well.
 
I tried this:

Screen.PreviousControl.SetFocus
Something = Screen.ActiveControl.SelText

but when you place the focus elsewhere the highlighted part goes away. So you might have to set variables from the lost focus (or some other) event for each text box (which is kind of why you probably wanted to use the ActiveControl so you didn't have to do that). So, sorry that I couldn't come up with a way for this to work. Maybe someone else will chime in.
 
hey thanks for taking a closer look.

I think I should now say why I want to do this so people can offer other ways of doing this.

I am using a translation API. Give it a word tell it the from and to language and it will translate the word.

I wanted to allow users to highlight any text on a form and then click a button to translate.

So does anyone have another way of doing this. I suppose shortcut key?
 
Might be simpler to have the user type [copy paste] the word they want to translate into a text box and run your translate code on the word the user types in. Might be an extra step for the user but should be a lot easier for you to program it and get it to work.
 
Thanks Ghudson, I agree that it is simple.

Actually I have just found a solution.

A picture has a click event but cannot get focus. Thus SOS solution will work if I use a picture as a "button".

great guys thanks.
 
Cool - good to know.
 

Users who are viewing this thread

Back
Top Bottom