textbox selecting text - no highlight

  • Thread starter Thread starter marfi95
  • Start date Start date
M

marfi95

I'm very confused. I'm trying to automatically select the text when
my textbox gets the focus. This is typically when the user has
clicked the mouse in the field.

This is the code I have in the Text1_GotFocus event:

Text1.SelectionStart = 0
Text1.SelectionLength = Text1.Text.Length

However, the text does not get highlighted. It appears to be the
"selectedtext" though because immediately after that I have a
Console.Writeline call printing text1.selectedtext and it is the
entire field. I just can't get it to highlight. Any ideas ????

Mark
 
Just do Text1.SelectAll()

I'm very confused. I'm trying to automatically select the text when
my textbox gets the focus. This is typically when the user has
clicked the mouse in the field.

This is the code I have in the Text1_GotFocus event:

Text1.SelectionStart = 0
Text1.SelectionLength = Text1.Text.Length

However, the text does not get highlighted. It appears to be the
"selectedtext" though because immediately after that I have a
Console.Writeline call printing text1.selectedtext and it is the
entire field. I just can't get it to highlight. Any ideas ????

Mark
 
Hi,

The textbox will not show the selection when textbox doesnt have
focus unless you set the hideselection property to true.
http://msdn.microsoft.com/library/d...wsformstextboxbaseclasshideselectiontopic.asp

Ken
---------------
I'm very confused. I'm trying to automatically select the text when
my textbox gets the focus. This is typically when the user has
clicked the mouse in the field.

This is the code I have in the Text1_GotFocus event:

Text1.SelectionStart = 0
Text1.SelectionLength = Text1.Text.Length

However, the text does not get highlighted. It appears to be the
"selectedtext" though because immediately after that I have a
Console.Writeline call printing text1.selectedtext and it is the
entire field. I just can't get it to highlight. Any ideas ????

Mark
 
i got problem ...i don't want highlighting i'm using gdi ...how do i et
get ridded of unwanted highlighting?

Dim txthelp As New TextBox
With txthelp
.Parent = Me
.SelectionStart = 0
.SelectionLength = .Text.Length
.BackColor = Color.White
.Dock = DockStyle.Fill
.WordWrap = True
.Multiline = True
.ScrollBars = ScrollBars.Vertical
.ReadOnly = True
.Text = "How to play MasterMind game." & vbCrLf & _
"The object of this game is to guess the sequence of four (4) coloured
pegs the computer has selected at random from the circled colours on the
right side field. " & vbCrLf & vbCrLf & _
"The computer chooses a secret combination of coloured pegs and can use
a colours more than once in the combination." & vbCrLf & _
"The computer pegs are hidden behind logo." & vbCrLf & vbCrLf & _
"You can have up to ten (10) guesses." & vbCrLf & _
"There are up to eight (8) Coloured pegs."
end with
regards
 
I understand that, but this is when the textbox GETS the focus that
its not highlighted. The user clicks the mouse in the text field,
which runs the code I have documented below, yet the selection is not
highlighted.

Thanks,
Mark
 
Back
Top