with vb6;
in a form
how can i move around the controls
using left & right / or up & down keys.
any advise please..
Printable View
with vb6;
in a form
how can i move around the controls
using left & right / or up & down keys.
any advise please..
Design time or run time?
at run time
Can you be more specific? What type of controls? Or are you only interested in a single control and if so, what type of control is that one? It matters.
i have the visualization like this
type of controls on my form
text & combo boxes and command buttons.
say for eg..
total controls are 10
on keypress i want to move between the controls basing
on their tab value. set the focus to the control
if key = vbtop or vbright then
(active control.tabindex + 1).setfocus
if key = vbbottom or vbleft then
(active control.tabindex - 1).setfocus
I don't think I fully understand... You do realize that is already built in? If a command button has the focus, pressing left or up arrows will set focus to the previous control in the tab order, assuming that control can get focus.
This will not work for textboxes. Since textboxes need the arrow keys to allow the user to move up/down, left/right along the lines and characters of the textbox. Same applies for listboxes and other controls where the navigation keys are designed to be used for keyboard navigation within the control.
how to code it please
i want to move around my bound controls
tab key is uni directional
hot key's not so fancy
preferable is up/down keys
i want to move above or below a control which is currently
having the focus
The tab key is not uni-directional, use the Shift key at the same time to go 'backwards'.
Most controls (such as textboxes and comboboxes) already use the arrow keys for other purposes, so it isn't a good idea to use the method you want for those controls - and presumably they are the majority of your controls, so it isn't worth using that method at all.
There aren't really any other valid keys to use either, the only 'safe' ones remaining will be ones like F8, which will not be intuitive at all.
If your program is going to be used by other people, the best thing to do is stick to normal Windows design guidelines - as most other programs already use them, so your users should already know what to do.
That includes setting an apt tab order for your controls, and using accelerator keys (eg: a label caption to "&Name" to allow Ctrl-N to focus the control next to it).
please tell me the general idea how to do..
i can get the value of active control tab index
me.activecontrol.tabindex
how can i move to a control like..
me.activecontrol.tabindex + 1 or
me.activecontrol.tabindex - 1
The closest you can do is loop through the Controls collection, and determine the control based on the TabIndex/TabStop/Enabled/Visible properties... then .SetFocus to the apt control.
I'm not going to help with code, because in my opinion you shouldn't be doing it.
Agree with si_the_geek.
Also, I am not even sure you can trap the arrow keys in the KeyDown or KeyAscii events? Those may not be passed by VB. If not passed then keyboard hooking may be needed & that complicates things quite a bit.
HTML Code:Public Sub focusser(frm As Form)
Dim currenttab As Integer
Dim ctl As Control
currenttab = frm.ActiveControl.TabIndex
If Not currenttab <= 0 Then
For Each ctl In frm.Controls
'assuming enables & visible with tabstop true
'not trapping any key
If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
ctl.TabIndex = (currenttab - 1) '
ctl.SetFocus ' here how to shift focus
End If
Next
End If
End Sub[B][/B]
HTML Code:Private Sub Form_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii & " <> tabIndex is : " & Me.ActiveControl.TabIndex
If KeyAscii = 14 Then
Call focusser(Me)
End If
End Sub
sir.... i got it
but what are the side effects i didn't know
HTML Code:Public Sub focusser(frm As Form)
Dim currenttab As Integer
Dim ctl As Control
currenttab = frm.ActiveControl.TabIndex
If Not currenttab <= 0 Then
For Each ctl In frm.Controls
'assuming enables & visible with tabstop true
'not trapping any key
If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
If ctl.TabIndex = (currenttab - 1) Then
ctl.SetFocus
End If
End If
Next
End If
End Sub
sir
whether can i use this code please
It's not a perfect solution, but it should be close...
Code:Private Sub Form_Load()
'Allow the form to capture the arrow keys before the controls.
Me.KeyPreview = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'If none of the modifiers are pressed (CTRL, SHIFT, ALT)...
If Shift = 0 Then
'If Down or Right, simulate pressing the TAB key.
'If Up or Left, simulate pressing the SHIFT+TAB keys.
Select Case KeyCode
Case vbKeyDown, vbKeyRight: SendKeys "{TAB}"
Case vbKeyUp, vbKeyLeft: SendKeys "+{TAB}"
End Select
End If
End Sub
thank you sir
is this code works fine with OS win XP & VISTHA as well