|
-
Feb 26th, 2009, 05:02 AM
#1
Thread Starter
New Member
[RESOLVED] AutoSelect when moving to textboxes
I use the code below for moving to textboxes in a form, with enter and backward with shift+tab. I want to be able to autoselect the value when moving to textboxes…
Thank you
Code:
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Enter AndAlso TypeOf Me.ActiveControl Is TextBox Then
Me.SelectNextControl(Me.ActiveControl, Not e.Shift, True, True, True)
End If
End Sub
-
Feb 26th, 2009, 05:14 AM
#2
Re: AutoSelect when moving to textboxes
Do you want to select all the text in the active textbox?
vb.net Code:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.Enter AndAlso TypeOf Me.ActiveControl Is TextBox Then Me.SelectNextControl(Me.ActiveControl, Not e.Shift, True, True, True) If TypeOf Me.ActiveControl Is TextBox Then DirectCast(Me.ActiveControl, TextBox).SelectAll() End If End Sub
-
Feb 26th, 2009, 06:49 AM
#3
Thread Starter
New Member
Re: AutoSelect when moving to textboxes
Thanks for your reply.. It is almost working…
The textboxes when I open my form are blank. I type a value in the first textbox and I move to next by pressing the enter. If I go back with shift tab it is not selecting all of my textbox. I have to compete a full “cyrcle” around my textboxes to start working.. Is there something else can be done..; I am trying to cath the Shift+Tab for e.keycode.. Can you provide some help..;
Thank you
-
Feb 26th, 2009, 07:17 AM
#4
Re: AutoSelect when moving to textboxes
Why dont you just set the TabIndex and TabStop property of each control, to be in your preferred order?, no code is needed to setup the Tab and Shift-Tab actions.
-
Feb 26th, 2009, 07:34 AM
#5
Thread Starter
New Member
Re: AutoSelect when moving to textboxes
The properties you are suggesting are in preffered order. The problem is, when I move to previous textbox with shift+tab it is not autoselecting the value of the textbox to start overwiting. I must select it with mouse to start overwiting. It happens only when I press shift+tab. The edited code provided before was very helpful and I want to catch and shift+tab keystroke.
-
Feb 26th, 2009, 08:13 AM
#6
Thread Starter
New Member
Re: AutoSelect when moving to textboxes
I think i found it...
Code:
Private Sub Form1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If Control.ModifierKeys = Keys.Shift And e.KeyCode = Keys.Tab Then
If TypeOf Me.ActiveControl Is TextBox Then DirectCast(Me.ActiveControl, TextBox).SelectAll()
End If
End Sub
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
|