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

Ken MacDonald drken567 at gmail.com
Wed Mar 24 21:54:05 CET 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100324/3de0273a/attachment.html>


More information about the Ironpython-users mailing list