By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

A nasty little TextBox

P: n/a
Hi there,

I'm trying to do an easy thing... but no luck so far...

I have a form with a textbox, and I want the following behaviour on mouse
click event:
-if no text is selected, select all
-if some (or all) text is selected, unselect all

This looks good... but doesn't work! :-(

Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Click
If TextBox1.SelectionLength > 0 Then
TextBox1.Select(0, 0)
Else
TextBox1.SelectAll()
End If
End Sub

I set a breakpoint on "TextBox1.Select(0,0)", never stops there; and I dont
see why?
How can I get the behaviour I want?

Please help me... to master this nasty TextBox!

Regards,
Mario
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Cor
Hi Mario,

Can it be that by clicking on the textbox you deselect everything?
:-)
You can make a seperate button to try or maybe use the mouse.down, I never
tried that (just a guess).

Cor
Nov 20 '05 #2

P: n/a
No, sorry, using a button is not acceptable, not it is sendkeys, or other
bogus workarrounds.

Thanks any way.

Regards,
Mario
"Cor" <no*@non.com> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
Hi Mario,

Can it be that by clicking on the textbox you deselect everything?
:-)
You can make a seperate button to try or maybe use the mouse.down, I never
tried that (just a guess).

Cor

Nov 20 '05 #3

P: n/a
Cor is right. Clicking the textbox deselects the text. Therefore, it will
always be zero. Try this it out. It works.

Dim hold As Integer

Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Click
If hold > 0 Then
TextBox1.Select(0, 0)
Else
TextBox1.SelectAll()
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Select(0, 5)
hold = TextBox1.SelectionLength
End Sub
"Cor" <no*@non.com> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
Hi Mario,

Can it be that by clicking on the textbox you deselect everything?
:-)
You can make a seperate button to try or maybe use the mouse.down, I never
tried that (just a guess).

Cor

Nov 20 '05 #4

P: n/a
Hi Brian,

Thank's. Not exactly like you said, but you gave me a good idea, to cache
the selection length.
Static hold As Integer
If hold > 0 Then
TextBox1.Select(0, 0)
hold = 0
Else
TextBox1.SelectAll()
hold = TextBox1.SelectionLength
End If
Regards,
Mario
"Brian" <no****@prairie.lakes.com> wrote in message
news:vp************@corp.supernews.com...
Cor is right. Clicking the textbox deselects the text. Therefore, it will
always be zero. Try this it out. It works.

Dim hold As Integer

Private Sub TextBox1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.Click
If hold > 0 Then
TextBox1.Select(0, 0)
Else
TextBox1.SelectAll()
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Select(0, 5)
hold = TextBox1.SelectionLength
End Sub
"Cor" <no*@non.com> wrote in message
news:uW**************@tk2msftngp13.phx.gbl...
Hi Mario,

Can it be that by clicking on the textbox you deselect everything?
:-)
You can make a seperate button to try or maybe use the mouse.down, I never tried that (just a guess).

Cor


Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.