Jump to content

Usage of _GUICtrlButton_SetImage


Recommended Posts

Good morning everyone. I'm trying to do a simple thing, but, for now, it seems to be very difficult... Maybe, I'm missing something, so I'm asking here.

I'm trying to let an image be clickable, so, I found out the _GUICtrlButton_SetImage function, which seems to very powerful. But for me, it doesn't work! 

$Motore1 = GUICtrlCreateButton("Something",10,10,58,54)
_GUICtrlButton_SetImage($Motore1,"C:\Dynamics\PIC\LOCALI_HVAC181 - Copia.jpg")

In this case, the image should fit in the button, right? Can someone help me out, please? Thanks :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • Moderators

FrancescoDiMuro,

If you create the button using the native function, then use the native function to set the image - see the script below.

Quote

I'm trying to let an image be clickable

Images are clickable - try clicking on both the button and image in this script:

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

$sImage = "M:\Program\AutoIt3\Examples\GUI\Advanced\Images\Red.bmp" ; Adjust to match your AutoIt installation path

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("", 10, 10, 80, 30, $BS_BITMAP)
GUICtrlSetImage($cButton, $sImage)

$cPic = GUICtrlCreatePic($sImage, 10, 100, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            MsgBox($MB_SYSTEMMODAL, "Button", "Button clicked")
        Case $cPic
            MsgBox($MB_SYSTEMMODAL, "Image", "Image clicked")
    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

Thank you M23! You're my Script Hero! Ahahahah :D Ok, I understood the use of native functions 

GUICtrlCreateButton

and 

GUICtrlSetImage

For the BMP... Are there any restrictions about the width and height of the image? And, If the image is in the same folder where the script is running, the function GUICtrlSetImage doesn't need the whole path where the image stands, is it right? Thank you M23. You're the one that manage to help me when I have problem with script... A very big thank you! :):):)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

  • Moderators

FrancescoDiMuro,

As far as I know there are no restrictions on the size of the BMP - just try with your image file and see if it works. And, yes, if the image file is in the same folder as the script then all you need is the filename.

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

FrancescoDiMuro,

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