Razraal Posted July 25, 2016 Posted July 25, 2016 Hey there. I want to create a button with an image. So far I've been unable to do it. Here's the code that creates the button and sets the image: $button = GUICtrlCreateButton ("", 10, 10, 40, 40) GUICtrlSetImage ($button, "my_image.jpg") Is there any other step I need to do?
Razraal Posted July 25, 2016 Author Posted July 25, 2016 Additional info: The "my_image.jpg" file is a 1024x1024 picture.
Razraal Posted July 25, 2016 Author Posted July 25, 2016 Additional info: Added the $BS_BITMAP style to the GUICtrlCreateButton. $button = GUICtrlCreateButton ("", 10, 10, 40, 40, $BS_BITMAP) GUICtrlSetImage ($button, "my_image.jpg") Still fails to show the image.
Moderators Melba23 Posted July 25, 2016 Moderators Posted July 25, 2016 (edited) Razraal, Welcome to the AutoIt forums. From the Help file for GUICtrlCreateButton: 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. So you need to add the style when creating the button: $button = GUICtrlCreateButton ("", 10, 10, 40, 40, $BS_BITMAP) GUICtrlSetImage ($button, "my_image.jpg") And add the #include <ButtonConstants.au3> line at the top of the script. M23 Edit 1: Our posts crossed. Is the image file in the same folder as the script? Edit 2: It seems that it does not work with jpg files - you need to convert it to a BMP. Sorry about that - I have never tried it with a jpg file. Edited July 25, 2016 by Melba23 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
Razraal Posted July 25, 2016 Author Posted July 25, 2016 11 minutes ago, Melba23 said: Edit 2: It seems that it does not work with jpg files - you need to convert it to a BMP. Sorry about that - I have never tried it with a jpg file. Hey there @Melba23, thanks for the welcoming! I've tried with a bmp image, also does not work. $button = GUICtrlCreateButton ("", 10, 10, 40, 40, $BS_BITMAP) GUICtrlSetImage ($button, "my_image.bmp") Converted the original jpg image through GIMP to a bmp image. Same resolution. Same result.
Moderators Melba23 Posted July 25, 2016 Moderators Posted July 25, 2016 Razraal, I have just tried with a large bmp file and I note that the image is displayed full-size, so only the very centre of the image is shown - which might lead you to think that there is nothing there. Obviously scaling is not done automatically as in the case of a picture control - you learn something new every day. You will need to rescale the image to the button size - putting a 1000x1000 image on a 40x40 button means you are not going to see much detail anyway. 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
Razraal Posted July 25, 2016 Author Posted July 25, 2016 3 minutes ago, Melba23 said: Razraal, I have just tried with a large bmp file and I note that the image is displayed full-size, so only the very centre of the image is shown - which might lead you to think that there is nothing there. Obviously scaling is not done automatically as in the case of a picture control - you learn something new every day. You will need to rescale the image to the button size - putting a 1000x1000 image on a 40x40 button means you are not going to see much detail anyway. M23 Thanks for your help mate, I appreciate it! I've decided to create an image control with GUICtrlCreateImage, instead of a button with an image, since the overal result is almost the same.
Moderators Melba23 Posted July 25, 2016 Moderators Posted July 25, 2016 Razraal, Delighted I could help. But when you reply in future, could you please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily. 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