|
-
Nov 26th, 2003, 08:02 AM
#1
Thread Starter
Lively Member
selecting text in the text box
I have a form with text boxs on it
whenever i enter(got focus) the textbox i want the text in it to be get selected
i can use textbox.selstart and textbox.sellenth but have many text boxs(48)
do i have to write it for each and every text box
(using VB net)
Please help
with Regards
sameer Mulgaonkar

-
Nov 26th, 2003, 08:12 AM
#2
you could add a handler for all the textboxes , then use SelectAll() , eg:
VB Code:
[Color=Blue]Private[/color] [Color=Blue]WithEvents[/color] tb [Color=Blue]As[/color] TextBox
[Color=Blue]Private[/color] [Color=Blue]Sub[/color] Form1_Load([Color=Blue]ByVal[/color] sender [Color=Blue]As[/color] System.Object, [Color=Blue]ByVal[/color] e [Color=Blue]As[/color] System.EventArgs) [Color=Blue]Handles[/color] [Color=Blue]MyBase[/color].Load
[Color=Blue]Dim[/color] ctl [Color=Blue]As[/color] Control
[Color=Blue]For[/color] [Color=Blue]Each[/color] ctl [Color=Blue]In[/color] [Color=Blue]Me[/color].Controls
[Color=Blue]If[/color] [Color=Blue]TypeOf[/color] ctl [Color=Blue]Is[/color] TextBox [Color=Blue]Then
[/color] [Color=Blue]AddHandler[/color] ctl.Enter, [Color=Blue]AddressOf[/color] tb_Enter
[Color=Blue]End[/color] [Color=Blue]If
[/color] [Color=Blue]Next
[/color] [Color=Blue]End[/color] [Color=Blue]Sub
[/color] [Color=Blue]Private[/color] [Color=Blue]Sub[/color] tb_Enter([Color=Blue]ByVal[/color] sender [Color=Blue]As[/color] [Color=Blue]Object[/color], [Color=Blue]ByVal[/color] e [Color=Blue]As[/color] System.EventArgs) [Color=Blue]Handles[/color] tb.Enter
[Color=Blue]Dim[/color] txtbox [Color=Blue]As[/color] TextBox = [Color=Blue]DirectCast[/color](sender, TextBox)
txtbox.SelectAll()
[Color=Blue]End[/color] [Color=Blue]Sub[/color]
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Nov 26th, 2003, 02:08 PM
#3
Lively Member
You could Also make your own control :
Create a new class myTextBox that inherits the class TextBox :
VB Code:
Public Class myTextBox
Inherits TextBox
Private Sub Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles mybase.Enter
mybase.SelectAll()
End Sub
End Class
-
Nov 27th, 2003, 12:31 AM
#4
Banned
hi
u can use select all property
like
textbox1.SelectAll()
Biswajit das
-
Nov 27th, 2003, 05:04 AM
#5
Thread Starter
Lively Member
tHANKS A LOTS I WILL TRY SELECTALL()
one more small thing how i can chatch page Up/page down on a SSTAB Control
with Regards
sameer Mulgaonkar

-
Dec 16th, 2004, 10:00 AM
#6
Frenzied Member
Re: selecting text in the text box
Is there a special trick for when a user clicks into the text box? 'Cause i can't get it to select everything when a user clicks in the text box.
Code:
Private Sub TextBox2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Enter
TextBox2.SelectAll()
End Sub
~Peter

-
Dec 16th, 2004, 11:56 AM
#7
PowerPoster
Re: selecting text in the text box
 Originally Posted by MrGTI
Is there a special trick for when a user clicks into the text box? 'Cause i can't get it to select everything when a user clicks in the text box.
Code:
Private Sub TextBox2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Enter
TextBox2.SelectAll()
End Sub
It does select it. You can copy it to another Text field. It just doesn't highlight it.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Dec 16th, 2004, 12:29 PM
#8
Frenzied Member
It does select it. You can copy it to another Text field. It just doesn't highlight it.
ooooooooh. So i guess i want to know how to highlight the text. My bad.
~Peter

-
Dec 16th, 2004, 01:12 PM
#9
PowerPoster
Re: selecting text in the text box
Hi,
"tHANKS A LOTS I WILL TRY SELECTALL()"
But you will still have to enter it a lot of times, or put a a lot of handles on.
Matt3011's suggestion means you do not have to write the code more than once.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Dec 16th, 2004, 01:23 PM
#10
-
Dec 16th, 2004, 06:31 PM
#11
PowerPoster
Re: selecting text in the text box
 Originally Posted by MrGTI
Any help in figuring out how to highlight the entire text in a TextBox when a user clicks in the text box?
Nothing i try will highlight the text (when a user clicks into a text box).
I've had no success with that either, but there must be a way. If we get no joy on this thread I will start a specific one.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Dec 17th, 2004, 02:59 AM
#12
Thread Starter
Lively Member
Re: selecting text in the text box
Thanks for the reply but one thing u missed that i know the selectall property but my promblem is i have all most 48 - 60 text box on the form and i don't want to repeat the code "Selectall"
with Regards
sameer Mulgaonkar

-
Dec 17th, 2004, 06:26 AM
#13
PowerPoster
Re: selecting text in the text box
 Originally Posted by sameer spitfire
Thanks for the reply but one thing u missed that i know the selectall property but my promblem is i have all most 48 - 60 text box on the form and i don't want to repeat the code "Selectall"
You have not indicated to which of the replies you are referring.
I repeat:
If you use Matt3011's suggestion you will only have to enter the code once.
Do you object to that?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Dec 17th, 2004, 09:55 AM
#14
PowerPoster
Re: selecting text in the text box
 Originally Posted by taxes
I've had no success with that either, but there must be a way. If we get no joy on this thread I will start a specific one.
Hi,
Looks like the ONLY event which doesn't highlight the text when you use SelectAll() is the GotFocus
Try it in Click, MouseDown, MouseUp etc.
With acknowledgments to Brownmonkey
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Dec 17th, 2004, 01:11 PM
#15
Frenzied Member
Re: selecting text in the text box
The GotFocus/Enter events don't work with SelectAll when you click into the text box. So i created a special procedure that i call from the MouseHover event.
~Peter

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|