The GW-Scripting list is a discussion list for information regarding the development and use of Window-Eyes scripts. Any subscriber of the GW-Scripting list has the ability to post on-topic messages.
From:
Chip OrangeSubject:
RE: How to set focus to a controlDate:
Sun, Jun 19, 2011 2:48:47 pmHi Christo,
Just as Bruce is doing, in the past I too have used the dialog creation
event to cause a certain control to be the one which starts out with focus.
Still, I went and checked through the list of dialog events just to be sure
I didn't see anything else more promising, and I'm afraid I did not. Only
dialog creation and dialog closing; all the rest are specific to a given
type of control.
If the editbox were disabled in your xml dialog properties, then I suppose
the focus would have no effect, but I can't think of any other reason why it
would not be working; unless this portion of your code is never getting
executed. it might be a good idea to put some sort of proof in this block
of code to show that it was being executed; place some sort of statement
immediately after your editbox focus perhaps that would indicate it had been
executed.
How about adding a statement that places text on the clipboard? this
wouldn't interfear with anything, and after the dialog opens, you could just
open a notepad window and paste the clipboard into it; if your text gets
pasted, then you know your focus got executed ok. below is such a line you
could add after your focus:
clipboard.text = "focus was executed."
hth,
Chip
-----Original Message-----
From: Christo de Klerk [mailto:christodeklerk@gmail.com]
Sent: Sunday, June 19, 2011 1:39 AM
To: gw-scripting@gwmicro.com
Subject: Re: How to set focus to a control
Hi Chip
I diligently follow your classes for which I am extremely grateful and when
I am happy with my app and can upload it, I will give you credit for it,
because it was through those classes that I have been able to do it.
The place you indicated seemed the logical place to me and it was the very
first place I tried, but for some reason it did not focus on the specified
edit box. I next tried it in my DisplayDialog sub, but still not. This isn't
a show stopper, but I would prefer to focus the edit box that I am trying to
do. Is there not perhaps an event I can test that will let me know that the
dialog is up and ready, because I might be trying to focus the control
before the dialog is quite ready for it?
Thanks for your invaluable help.
Kind regards
Christo
On 2011/06/18 9:23 PM, Chip Orange wrote:
Just as Bruce is doing, in the past I too have used the dialog creation
event to cause a certain control to be the one which starts out with focus.
Still, I went and checked through the list of dialog events just to be sure
I didn't see anything else more promising, and I'm afraid I did not. Only
dialog creation and dialog closing; all the rest are specific to a given
type of control.
If the editbox were disabled in your xml dialog properties, then I suppose
the focus would have no effect, but I can't think of any other reason why it
would not be working; unless this portion of your code is never getting
executed. it might be a good idea to put some sort of proof in this block
of code to show that it was being executed; place some sort of statement
immediately after your editbox focus perhaps that would indicate it had been
executed.
How about adding a statement that places text on the clipboard? this
wouldn't interfear with anything, and after the dialog opens, you could just
open a notepad window and paste the clipboard into it; if your text gets
pasted, then you know your focus got executed ok. below is such a line you
could add after your focus:
clipboard.text = "focus was executed."
hth,
Chip
-----Original Message-----
From: Christo de Klerk [mailto:christodeklerk@gmail.com]
Sent: Sunday, June 19, 2011 1:39 AM
To: gw-scripting@gwmicro.com
Subject: Re: How to set focus to a control
Hi Chip
I diligently follow your classes for which I am extremely grateful and when
I am happy with my app and can upload it, I will give you credit for it,
because it was through those classes that I have been able to do it.
The place you indicated seemed the logical place to me and it was the very
first place I tried, but for some reason it did not focus on the specified
edit box. I next tried it in my DisplayDialog sub, but still not. This isn't
a show stopper, but I would prefer to focus the edit box that I am trying to
do. Is there not perhaps an event I can test that will let me know that the
dialog is up and ready, because I might be trying to focus the control
before the dialog is quite ready for it?
Thanks for your invaluable help.
Kind regards
Christo
On 2011/06/18 9:23 PM, Chip Orange wrote:
Hi Christo,
below is some code taken from class #14 of the scripting class
examples. it shows the general skeleton SELECT CASE statement which
your dialog event handler will probably use, and when you figure out
it's not a particular control which caused your event, then you test
for whether the dialog is just being created or is closing. if it's
just being created, that's where you usually put your first focus
command; load up your editbox and set it's position, and so on. If
you are following the classes, and would like me to cover the
particulars of working with different control types, then just let me
know.
Select Case dId
Case "your control ID"
' ...
Case Else
' no control ID was recognized
' in this portion we test on events not related to a specific control
If dEvent = dialogCreated Then
' this event happens before all others, and is the dialog being
created ' now initialize your various controls in the dialog ' ...
place your initialization code here
DialogEventHandler = True
ExitFunction
ElseIf dEvent = dialogClosing Then
' something caused this dialog to close, and now it's closing, set
your global variable for this dialog or whatever else you need to do
DialogEventHandler = True
ExitFunction
End If
End Select
as for putting the insertion point at the end of an editbox, it helps
to know that when there is nothing selected in an editbox, the
selectionStart and selectionEnd properties both point to the insertion
point; so, just set both of these properties (you can see the editbox
properties by going to the control object in the manual, and in there
is an entry for "control Types", where you can find the editbox), to
the end of the text in the editbox. I think you can guess this value
by looking at the length of the text property, and subtracting 1,
since the selection properties are 0 based (that is, the first
position is 0, not 1). so, if you have put your editbox control
object into a variable named eb, you'd do something like this to put the
cursor at the end:
eb.focus
if len(eb.text)> 0 then
eb.selectionStart = len(eb.text)-1
eb.selectionEnd = len(eb.text)-1
end if
I'm just guessing about subtracting 1, so if you find yourself just
before the last character, then don't do the subtraction.
hth,
Chip
-----Original Message-----
From: Christo de Klerk [mailto:christodeklerk@gmail.com]
Sent: Saturday, June 18, 2011 1:58 PM
To: gw-scripting@gwmicro.com
Cc: BT
Subject: Re: How to set focus to a control
Hi Bruce
Many thanks for this. That was helpful.
I have two additional question, if you or anyone could help please:
1. Where do I put the statement to set focus to a specific controlright.
when the dialog is displayed for the very first time. I can't get that
What would be the best event to test for that?
2. Is there a way to place the cursor at the end of an edit box
instead of at the beginning as the Focus() method does?
Kind regards
Christo
On 2011/06/18 6:29 PM, BT wrote:
Hi Again Cristo,
Below is the dialog box area that it focuses to. This is togive you a complete picture of what ID and such I mean. above this
point is where the edit boxes are and you would do the same thing,but remember to include the entire ID name to focus to.
Bruce
> widthclass="btn"> Browse For File...
> widthclass="btn"> Save Sound File> widthclass="btn"> Cancel Sound File
> widthclass="btn"> Test Sound File> widthclass="btn"> Copy Sound File To Default
> widthclass="btn"> Info On Sound File
Sent: Saturday, June 18, 2011 12:23 PM
Subject: Re: How to set focus to a control
Hi christo!
Below is my cuckoo clock program and the use of the Browsfunction and note at the bottom I focus on the save button...
This bit of code firsts has you scan for a file, if one
selected it copies the file name and path to there fields in thedialog then after all of that I focus on the save button to give yousave and exit.
the option to
It goes to the dialog object using the Control command of itand going to the ID name of the focus button.
Bruce
Case "btn_browse"
If dEvent = buttonClicked Then' The browse button was clicked, so we'll prompt for the filename
' The default path is the client default folder.editSoundFile = CommonFileDialog(True, myStrings( editName&
"_Sound_Title"), myStrings( editName& "_Default_Sound_File"),ClientInformation.ScriptPath, "WAV Files, *.wav", 1, ".wav",
cfdfFileMustExist + cfdfHideReadOnlyCheck, dObj.Window)If Len( editSoundFile)> 0 Then
' dObj.Control( "edit_sound").Text = editSoundFiledObj.Control( "edit_sound").Text = GetFileName( editSoundFile)
dObj.Control( "edit_sound_path").Text = GetFilePath( editSoundFile)Else
editSoundFile = dObj.Control( "edit_sound_path").Text&dObj.Control( "edit_sound").Text
End IfdObj.Control( "btn_sound_save").Focus()
End IfSoundDialogProc = True
Exit Function
Sent: Saturday, June 18, 2011 10:41 AMSubject: How to set focus to a control
Hi scripters
How can I set the focus to a particular control in a dialog? I wantto place the cursor in a specific editbox. Does the control have
something like a setfocus method?
Kind regards
Christo




