Jump to content

Button inside Lable


DigDeep
 Share

Recommended Posts

Not sure what am I doing wrong here...

I want to click on the $Lable1 to get the $Button1 (This works)

When the Button comes up, I want to click it to get msgbox or whatever actions needed. (This does not work)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>

#Region
$Form2 = GUICreate("Form2", 350, 198, 766, 621)
$Label1 = GUICtrlCreateLabel("Label1", 32, 24, 108, 33)
GUISetState(@SW_SHOW)
#EndRegion

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Label1
            $Button1 = GUICtrlCreateButton("Button1", 136, 144, 75, 25)

            Select
                Case $Button1 = MouseClick($MOUSE_CLICK_LEFT)
                    MsgBox(0, '', 'Button Selected')
            EndSelect

    EndSwitch
WEnd

 

Link to comment
Share on other sites

  • Moderators

DigDeep,

Perhaps like this:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

; Cretae placeholder for non-existent button - otherwise it will fire on every pass through the idle loop
Global $Button1 = 9999

$Form2 = GUICreate("Form2", 350, 198, 766, 621)
$Label1 = GUICtrlCreateLabel("Label1", 32, 24, 108, 33)

GUISetState(@SW_SHOW)

While 1
    
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Label1
            ;Disable label
            GUICtrlSetState($Label1, $GUI_DISABLE)
            ; Create button
            $Button1 = GUICtrlCreateButton("Button1", 136, 144, 75, 25)

        Case $Button1
            ; Delete button
            GUICtrlDelete($Button1)
            ; Display MsgBox
            MsgBox($MB_SYSTEMMODAL, '', 'Button Selected')
            ; Re-enable label
            GUICtrlSetState($Label1, $GUI_ENABLE)
    EndSwitch
    
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi Melba,

I think it was because of the Global $Button1 not declaring at the top was creating the issue.

I was able to get it your way now.

Sorry had to take more time here but I tried to adjust it again but it went off again for not displaying the msgbox.

1. I am using Select and not Switch format.

2. When Lable is clicked it will check if the testing.txt file exists or not. If yes then it will get the Button.

3. When the Button is clicked it will display the msgbox.

 

If I remove the 'If Fileexists' and below that Select part, it works fine. Something like this...

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit

        Case $nMsg = $Label1
;~          If FileExists('C:\Temp\testing.txt') Then
            $Button1 = GUICtrlCreateButton("Button1", 136, 144, 75, 25)

;~          Select
        Case $nMsg = $Button1
            ; Display MsgBox
            MsgBox($MB_SYSTEMMODAL, '', 'Button Selected')
;~          EndSelect
;~          EndIf

    EndSelect

WEnd

But I want the button to show only if the file exists and then the msgbox when button is clicked. And the below one does not work...

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

; Cretae placeholder for non-existent button - otherwise it will fire on every pass through the idle loop
Global $Button1 = 9999

$Form2 = GUICreate("Form2", 350, 198, 766, 621)
$Label1 = GUICtrlCreateLabel("Label1", 32, 24, 108, 33)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit

        Case $nMsg = $Label1
            If FileExists('C:\Temp\testing.txt') Then
                $Button1 = GUICtrlCreateButton("Button1", 136, 144, 75, 25)

                Select
                    Case $nMsg = $Button1
                        ; Display MsgBox
                        MsgBox($MB_SYSTEMMODAL, '', 'Button Selected')
                EndSelect
            EndIf

    EndSelect

WEnd

 

Edited by DigDeep
Link to comment
Share on other sites

  • Moderators

DigDeep,

Why the second Select structure?

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

; Cretae placeholder for non-existent button - otherwise it will fire on every pass through the idle loop
Global $Button1 = 9999

$Form2 = GUICreate("Form2", 350, 198, 766, 621)
$Label1 = GUICtrlCreateLabel("Label1", 32, 24, 108, 33)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit

        Case $nMsg = $Label1
            If FileExists('C:\Temp\testing.txt') Then
                $Button1 = GUICtrlCreateButton("Button1", 136, 144, 75, 25)
            EndIf

        Case $nMsg = $Button1
            ; Display MsgBox
            MsgBox($MB_SYSTEMMODAL, '', 'Button Selected')

    EndSelect

WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

DigDeep,

Glad I could help.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...