Jump to content

Recommended Posts

Posted (edited)

So normally you can use the arrow keys in a GUI to walk through all the controls, not unlike the tab key. But I recently realized that if you put a Pic control in the midst of your normal controls it interrupts the ability to move through the controls (the tab key still works). I really liked the arrow key functionality, and I'm wondering if there's a way to restore that capability without capturing and processing the arrow keys manually, or just moving the Pic creation to a different part of the code.

I've whipped up a bit of code with some examples:

#include <GUIConstants.au3>

$sPic = StringLeft(@AutoItExe, StringInStr(@AutoItExe, '\', 0, -1)) & '\Examples\GUI\logo4.gif'

; This is the normal behaviour I'd like to keep.
GUICreate('Good Example', 250, 150, @DesktopWidth/2 - 250)
GUICtrlCreateButton('Button', 50, 0, 200, 30)
GUICtrlCreateButton('Button', 50, 30, 200, 30)
GUICtrlCreateButton('Button', 50, 60, 200, 30)
GUICtrlCreateButton('Button', 50, 90, 200, 30)
GUICtrlCreateButton('Button', 50, 120, 200, 30)
GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd
GUIDelete()


; This is the bad behaviour I'd like to avoid.
GUICreate('Example 2', 250, 150, @DesktopWidth/2 - 250)
GUICtrlCreatePic($sPic, 0, 0, 50, 30)
GUICtrlCreateButton('Button', 50, 0, 200, 30)
GUICtrlCreatePic($sPic, 0, 30, 50, 30)
GUICtrlCreateButton('Button', 50, 30, 200, 30)
GUICtrlCreatePic($sPic, 0, 60, 50, 30)
GUICtrlCreateButton('Button', 50, 60, 200, 30)
GUICtrlCreatePic($sPic, 0, 90, 50, 30)
GUICtrlCreateButton('Button', 50, 90, 200, 30)
GUICtrlCreatePic($sPic, 0, 120, 50, 30)
GUICtrlCreateButton('Button', 50, 120, 200, 30)
GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd
GUIDelete()


; This is almost what I want, but notice it doesn't "loop" around like the first example.
; And also having to create the pictures out of sequence with the buttons is not ideal.
GUICreate('Example 3', 250, 150, @DesktopWidth/2 - 250)
GUICtrlCreateButton('Button', 50, 0, 200, 30)
GUICtrlCreateButton('Button', 50, 30, 200, 30)
GUICtrlCreateButton('Button', 50, 60, 200, 30)
GUICtrlCreateButton('Button', 50, 90, 200, 30)
GUICtrlCreateButton('Button', 50, 120, 200, 30)

GUICtrlCreatePic($sPic, 0, 0, 50, 30)
GUICtrlCreatePic($sPic, 0, 30, 50, 30)
GUICtrlCreatePic($sPic, 0, 60, 50, 30)
GUICtrlCreatePic($sPic, 0, 90, 50, 30)
GUICtrlCreatePic($sPic, 0, 120, 50, 30)
GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd
GUIDelete()

The first GUI that opens demonstrates the behaviour I like. The second GUI demonstrates the problem. The third GUI is almost a solution, but the focus won't wrap around (eg: You can't just hold the down arrow and have the focus loop through the buttons, it sticks at the end). Also creating the pic controls out of sequence with the buttons makes my code harder to read.

Edited by therks
Posted (edited)
19 hours ago, therks said:

The third GUI is almost a solution, but the focus won't wrap around

Put pic controls in a separate group

...
GUICreate('Example 3', 250, 150, @DesktopWidth/2 - 250)
GUICtrlCreateButton('Button', 50, 0, 200, 30)
GUICtrlCreateButton('Button', 50, 30, 200, 30)
GUICtrlCreateButton('Button', 50, 60, 200, 30)
GUICtrlCreateButton('Button', 50, 90, 200, 30)
GUICtrlCreateButton('Button', 50, 120, 200, 30)
GUIStartGroup() ; <== add
GUICtrlCreatePic($sPic, 0, 0, 50, 30)
GUICtrlCreatePic($sPic, 0, 30, 50, 30)
GUICtrlCreatePic($sPic, 0, 60, 50, 30)
GUICtrlCreatePic($sPic, 0, 90, 50, 30)
GUICtrlCreatePic($sPic, 0, 120, 50, 30)
GUISetState()
...

 

Edited by InnI

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...