Results 1 to 16 of 16

Thread: Move arround the controls

  1. #1

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question 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..

  2. #2
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Move arround the controls

    Design time or run time?
    Option Explicit should not be an Option!

  3. #3

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question Re: Move arround the controls

    at run time

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question 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

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question 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

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

  9. #9

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question 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

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question 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

  13. #13

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question 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

  14. #14

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question Re: Move arround the controls

    sir
    whether can i use this code please

  15. #15
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Lightbulb 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

  16. #16

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question 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
  •  



Click Here to Expand Forum to Full Width