|
-
Aug 25th, 2009, 05:42 AM
#1
Thread Starter
PowerPoster
Move arround the controls
with vb6;
in a form
how can i move around the controls
using left & right / or up & down keys.
any advise please..
-
Aug 25th, 2009, 08:06 AM
#2
Frenzied Member
Re: Move arround the controls
Option Explicit should not be an Option!
-
Aug 25th, 2009, 09:01 AM
#3
Thread Starter
PowerPoster
Re: Move arround the controls
-
Aug 25th, 2009, 09:26 AM
#4
Re: Move arround the controls
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.
-
Aug 25th, 2009, 09:43 AM
#5
Thread Starter
PowerPoster
Re: Move arround the controls
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
-
Aug 25th, 2009, 09:51 AM
#6
Re: Move arround the controls
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.
-
Aug 25th, 2009, 10:03 AM
#7
Thread Starter
PowerPoster
Re: Move arround the controls
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
Last edited by make me rain; Aug 25th, 2009 at 10:04 AM.
Reason: spell mistake
-
Aug 25th, 2009, 10:30 AM
#8
Re: Move arround the controls
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).
-
Aug 25th, 2009, 11:19 AM
#9
Thread Starter
PowerPoster
Re: Move arround the controls
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
-
Aug 25th, 2009, 11:41 AM
#10
Re: Move arround the controls
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.
-
Aug 25th, 2009, 11:48 AM
#11
Re: Move arround the controls
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.
-
Aug 25th, 2009, 12:34 PM
#12
Thread Starter
PowerPoster
Re: Move arround the controls
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
-
Aug 25th, 2009, 12:50 PM
#13
Thread Starter
PowerPoster
Re: Move arround the controls
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
-
Aug 27th, 2009, 03:30 AM
#14
Thread Starter
PowerPoster
Re: Move arround the controls
sir
whether can i use this code please
-
Aug 27th, 2009, 12:33 PM
#15
Hyperactive Member
Re: Move arround the controls
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
-
Aug 28th, 2009, 02:25 AM
#16
Thread Starter
PowerPoster
Re: Move arround the controls
thank you sir
is this code works fine with OS win XP & VISTHA as well
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
|