[IronPython] focus and selecting text in a TextBox with IronPython

Ken MacDonald drken567 at gmail.com
Tue Apr 6 07:14:03 PDT 2010


Hi Jimmy,
Thanks; this thread looks quite interesting and very close to what I want to
do. Off chasing something else after I implemented a kind-of-lame
workaround, but this looks like an excellent place to make some more
progress when I get back onto this problem.
Ken

On Tue, Apr 6, 2010 at 2:42 AM, Jimmy Schementi <
Jimmy.Schementi at microsoft.com> wrote:

> Does the equivalent C#/VB code work? I’d think not; it’s just a matter of
> using the TextBox selection APIs correctly. This sounds like a similar
> issue:
> http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/81b43024-6164-43c7-a6b6-e2f55c9412c8.
> Basically, I think you need to call Focus() again after selecting the text
> programmatically; I ran into the same issue while building my RubyConf demo:
>
> http://github.com/jschementi/rubyconf2009/blob/master/sketchscript/features/start.rb#L204.
>
>
>
>
> ~js
>
>
>
> *From:* users-bounces at lists.ironpython.com [mailto:
> users-bounces at lists.ironpython.com] *On Behalf Of *Ken MacDonald
> *Sent:* Wednesday, March 24, 2010 1:54 PM
> *To:* Discussion of IronPython
> *Subject:* [IronPython] focus and selecting text in a TextBox with
> IronPython
>
>
>
> I'm trying to capture the event of focus being shifted into a text box via
> mouse click, and would like to highlight the existing text, so that if I
> start typing the selected text will disappear. i.e. the the box initially
> contains "<Enter Name>", I click into the box, "<Enter Name>" is
> highlighted, and if I type "fred" the initial text will disappear, leaving
> only "fred". I can capture the focus with:
>
> textbox.GotKeyboardFocus += name_keyboard_focus
>
> but this handler is doing something wrong:
>
>     def name_keyboard_focus(self, sender, args):
>         #alert("got focus!")
>         textbox = self.control("NewName")
>         textbox.Focus()
>         textbox.SelectAll()
>
> If I add:
>
>         textbox.Cut()
>
> or:
>         alert(textbox.SelectedText)
>
> at the end, it's obvious that the SelectAll() has worked, but the text is
> NOT highlighted, and if I type "fred" I get "fred" appended to the original
> text, "<Enter Name>fred".
>
> Any clues appreciated.
> Ken
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ironpython.com/pipermail/users-ironpython.com/attachments/20100406/b9de58a3/attachment.htm>


More information about the Users mailing list