Sign in to follow this  
Followers 0
qwert

Why isn't my Button2 detected?

4 posts in this topic

I have a button on a GUI that isn't working, so I prepared the following greatly simplified test case. Button1 works. Button2 doesn't. Why not?

#include <GUIConstants.au3>

$GUI = GUICreate("Text Position Test", 300, 200, -1, -1)
$Label = GUICtrlCreateLabel("Long strings of displayed text need to start at the beginning ... but so do short strings.", 20, 120, 200, 60)
$Entry = GUICtrlCreateInput("", 100, 40, 100, 20)

$Button_1 = GUICtrlCreateButton ("Run Notepad",  40, 80, 80,20)
$Button_2 = GUICtrlCreateButton ("Button Test",  40, 160, 80,20)

GUISetState () 

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            GUICtrlSetData($Entry, "This is an example of long text that exceeds the viewable area")
            Run('Notepad.exe')    ; Will Run/Open Notepad
        Case $msg = $Button_2
            MsgBox(0, "Testing", "Button 2 was pressed")    ; Will demonstrate Button 2 being pressed
            GUICtrlSetData($Entry, "This is short text")
    EndSelect
Wend

Obviously, it's something basic -- but I can't see it. Somehow the placing of text in the entry field interferes with Button2 only.

Thanks for any help.

Share this post


Link to post
Share on other sites



Your Button2 is "under" the label that's why you can't press it.

This works: (moved the button further down)

#include <GUIConstants.au3>

$GUI = GUICreate("Text Position Test", 300, 250, -1, -1)
$Label = GUICtrlCreateLabel("Long strings of displayed text need to start at the beginning ... but so do short strings.", 20, 120, 200, 60)
$Entry = GUICtrlCreateInput("", 100, 40, 100, 20)

$Button_1 = GUICtrlCreateButton ("Run Notepad",  40, 80, 80,20)
$Button_2 = GUICtrlCreateButton ("Button Test",  40, 200, 80,20)

GUISetState () 

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            GUICtrlSetData($Entry, "This is an example of long text that exceeds the viewable area")
            ;Run('Notepad.exe')    ; Will Run/Open Notepad
        Case $msg = $Button_2
            MsgBox(0, "Testing", "Button 2 was pressed")    ; Will demonstrate Button 2 being pressed
            GUICtrlSetData($Entry, "This is short text")
    EndSelect
Wend

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

its a very simple and very common problem if its under a alabel or a pic control...

Share this post


Link to post
Share on other sites

Your Button2 is "under" the label that's why you can't press it.

That explains why it worked every time I took out the label statement -- but I didn't make the connection about field overlap.

Thank you very much.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0