<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hello Ken,<br>
<br>
You don't say whether you are using WPF, Windows Forms or Silverlight.
When I've written code similar to your with windows forms and always
used SelectionStart and SelectionLength.<br>
<br>
All the best,<br>
<br>
Michael<br>
<br>
On 24/03/2010 20:54, Ken MacDonald wrote:
<blockquote
 cite="mid:3468cae11003241354l60bd213ejd449aa23921bf990@mail.gmail.com"
 type="cite">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 "&lt;Enter Name&gt;", I
click into the box, "&lt;Enter Name&gt;" is highlighted, and if I type
"fred" the initial text will disappear, leaving only "fred". I can
capture the focus with:<br>
  <br>
textbox.GotKeyboardFocus += name_keyboard_focus<br>
  <br>
but this handler is doing something wrong:<br>
  <br>
&nbsp;&nbsp;&nbsp; def name_keyboard_focus(self, sender, args):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #alert("got focus!")<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textbox = self.control("NewName")<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textbox.Focus()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textbox.SelectAll()<br>
  <br>
If I add:<br>
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; textbox.Cut()<br>
  <br>
or:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(textbox.SelectedText)<br>
  <br>
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, "&lt;Enter Name&gt;fred".<br>
  <br>
Any clues appreciated.<br>
Ken<br>
  <br>
  <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a>
<a class="moz-txt-link-freetext" href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a>
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a>
<a class="moz-txt-link-freetext" href="http://www.voidspace.org.uk/blog">http://www.voidspace.org.uk/blog</a>

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (&#8221;BOGUS AGREEMENTS&#8221;) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.

</pre>
</body>
</html>