mr-es335 Posted November 18, 2023 Posted November 18, 2023 (edited) Good day, After some 2 hours, I could not locate a simple and direct response to my question, "How do I place an image on a button in AutoIt?" Rather frustrating indeed! So, I am providing what I hope will be a simple "response-and-guide" in answer to my query. • Both the script and the image are being provided. • Other hopefully relevant information is provided below the actual script ; ----------------------------------------------- #include <ButtonConstants.au3> #include <FontConstants.au3> #include <GUIConstantsEx.au3> ; ----------------------------------------------- Local $hGUI = GUICreate("Button Image Test", 345, 65) ; The width and height of the dialog box.[1] GUISetFont(12, $FW_BOLD, $GUI_FONTNORMAL, "Calibri") ; The size and the type of font being employed. [2] Local $MyButton = GUICtrlCreateButton("", 20, 20, 150, 25, $BS_BITMAP) ; The postion, size and the GUI Control Styles of the button. [3] GUICtrlSetImage($MyButton, "my_image.bmp") ; The actual image [4] Local $Exit = GUICtrlCreateButton("Exit Me Please!", 175, 20, 150, 25) ; As $MyButton, but with no image. ; ----------------------------------------------- GUISetState(@SW_SHOW, $hGUI) ; Display the dialog box. ; ----------------------------------------------- While 1 ; To "catch" any-and-all of the button events. Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $Exit ExitLoop ; What occurs when the Exit button is selected. Case $MyButton MyFunc() ; I simply wanted something to occur when $MyButton is selected. EndSwitch WEnd ; ----------------------------------------------- Func MyFunc() ; In response to the selection of $MyButton. MsgBox(0, 'MyButton', 'Inside MyFunc()') EndFunc ;==>MyFunc ; ----------------------------------------------- ; Observations ; [1] This dialog displays what I refer to as a 1x2 button dialog...that is, 1 button high by two buttons wide! ; [2] I do tend to prefer the Calibri font for all of my button texts. See GUISetFont in the HelpFile. ; [3] Go to the HelpFile and locate GUICtrlCreateButton. For "style" select "GUI Control Styles Appendix". ; [4] As the image is stored within the folder where the script is located,...no "path" is required. 1x2.au3 my_image.bmp I sincerely hope that the above information will be of some practicable use to others? "A teacher takes a hand, opens a mind, and touches a heart." Edited November 18, 2023 by mr-es335 mr-es335 Sentinel Music Studios
Solution mr-es335 Posted November 19, 2023 Author Solution Posted November 19, 2023 Good day, Any comments...anyone? mr-es335 Sentinel Music Studios
argumentum Posted November 19, 2023 Posted November 19, 2023 On 11/18/2023 at 10:26 AM, mr-es335 said: After some 2 hours, I could not locate a simple and direct response to my question, "How do I place an image on a button in AutoIt?" Rather frustrating indeed! https://www.google.com/search?q=autoit+%24BS_BITMAP This post is good but is not like there was no examples in the forums. Nonetheless thanks for a well documented example. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Moderators Melba23 Posted November 19, 2023 Moderators Posted November 19, 2023 2 hours ago, mr-es335 said: Any comments...anyone? Yes, please do not post simple scripts such as this when there is an essentially similar example in the help file and there is a direct link between GUICtrlCreateButton and GUICtrlSetImage which should lead you straight to the solution. Thanks in advance for your cooperation. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
mr-es335 Posted November 19, 2023 Author Posted November 19, 2023 Melba23, I very much respectfully disagree...I personally tend to find many of the example in the HelpFile - at least to me anyhow...confusing! Please note: The use of italics and underlines are intentional and theretofore, purposeful! It is imperative that I do not come across as "crass" or, in any way "disrespectful". mr-es335 Sentinel Music Studios
Moderators Melba23 Posted November 19, 2023 Moderators Posted November 19, 2023 mr-es335, The Help File example: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> Example() Func Example() GUICreate("My GUI") ; will create a dialog box that when displayed is centered GUICtrlCreateButton("my picture button", 10, 20, 40, 40, $BS_ICON) GUICtrlSetImage(-1, "shell32.dll", 22) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc ;==>Example Please explain what is confusing about that code taken directly from the GUICtrlSetImage page. Concerning the "placing an image on a button" problem, I can see little difference between it and the code you posted in the OP. Your "something to occur" when the button is pressed code is already covered on the GUICtrlCreateButton page - which includes the following text: Quote A Button control can display an icon or image by using the $BS_ICON or $BS_BITMAP style. Use GUICtrlSetImage() to specify the picture to use. Which, as you can see, has a direct link to the function. This is a serious question - we want the examples in the Help file to be understandable to even complete beginners. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
mr-es335 Posted November 19, 2023 Author Posted November 19, 2023 Melba, I did read both texts...and I personally, simply do not see the provided content being as "simple" as you suggest! Many times, what I read is exactly the obvious. All that I wanted to do was to insert an image on a button. I did not want to delve into the differences between an image and an icon. If there are various options, it might be preferable to provide more than one example...as is done with other examples in the HelpFile. I do hope that this makes sense? mr-es335 Sentinel Music Studios
Moderators Melba23 Posted November 20, 2023 Moderators Posted November 20, 2023 mr-es335, Thank you for responding. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now