I am trying to "highlight" text in a TextBox control during the "Enter" event as follows

private void txtPriorPlantTotal_Enter(object sender, System.EventArgs e

this.txtPriorPlantTotal.SelectionStart = 0
this.txtPriorPlantTotal.SelectionLength = this.txtPriorPlantTotal.Text.Length


However, when I run the program and click on the textbox none of the text is physicaly highlighted. SelectedText shows I have selected all the text in the textbox but nothing is highlighted. I tried a few other textboxes just to make sure it wasn't the control

What gives

C# with framework 1.1

Re: Highlight Textbox Text by hirf-spam-me-here

hirf-spam-me-here
Fri Apr 23 09:58:17 CDT 2004

* "=?Utf-8?B?Q2hyaXMgQ2xpbmU=?=" <chrisc@hackettpublishing.com> scripsit:
> I am trying to "highlight" text in a TextBox control during the "Enter" event as follows:
>
> private void txtPriorPlantTotal_Enter(object sender, System.EventArgs e)
> {
> this.txtPriorPlantTotal.SelectionStart = 0;
> this.txtPriorPlantTotal.SelectionLength = this.txtPriorPlantTotal.Text.Length;
> }
>
> However, when I run the program and click on the textbox none of the
> text is physicaly highlighted. SelectedText shows I have selected all
> the text in the textbox but nothing is highlighted. I tried a few other
> textboxes just to make sure it wasn't the control.

Try to call the control's 'SelectAll' method. If this doesn't work, add
the code to the control's 'GotFocus' event handler.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Re: Highlight Textbox Text by anonymous

anonymous
Fri Apr 23 10:36:02 CDT 2004

I have tried using the SelectAll and it still doesn't "highlight" any text
I also tried using the GotFocus event and still nothing. I can see the event being fired and the SelectedText show I have the text but still nothing is highlighted



Re: Highlight Textbox Text by Behram

Behram
Sun Apr 25 18:18:26 CDT 2004

Use TextLength (is one word) instead of Text.Length (note the missing dot)
and it should work. In your example:

Change this line ...

this.txtPriorPlantTotal.SelectionLength =
this.txtPriorPlantTotal.Text.Length;

to ...

this.txtPriorPlantTotal.SelectionLength =
this.txtPriorPlantTotal.TextLength;


Ciao

--

Best Regards - Behram
"Chris Cline" <anonymous@discussions.microsoft.com> wrote in message
news:2F9B6122-70EA-47C6-858E-2D58E1D89BE2@microsoft.com...
> I have tried using the SelectAll and it still doesn't "highlight" any
text.
> I also tried using the GotFocus event and still nothing. I can see the
event being fired and the SelectedText show I have the text but still
nothing is highlighted.
>
>