Jump to content

A customized button with image and label ?!?


Armand
 Share

Recommended Posts

how do i make a click-able button with a BG image set and place some text on it ?

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiButton.au3>
;

$hGUI   = GUICreate("Button With Icons + Text")

$btn1   = _GUICtrlCreateButton("Button1", 10, 10, 90, 25, -1, -1, "shell32.dll", 6, $BUTTON_IMAGELIST_ALIGN_LEFT)
$btn2   = _GUICtrlCreateButton("Button2", 10, 50, 90, 25, -1, -1, "shell32.dll", 21, $BUTTON_IMAGELIST_ALIGN_RIGHT)
$btn3   = _GUICtrlCreateButton("Button3", 10, 90, 50, 50, -1, -1, "shell32.dll", 32, $BUTTON_IMAGELIST_ALIGN_TOP)
$btn4   = _GUICtrlCreateButton("Button4", 10, 140, 50, 50, -1, -1, "shell32.dll", 14, $BUTTON_IMAGELIST_ALIGN_BOTTOM)

GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Exit

Func _GUICtrlCreateButton($sText,$iLeft,$iTop,$iWidth=-1,$iHeight=-1,$nStyle=-1,$nExStyle=-1,$sIconFile='', $nIconID=0, $nAlign=-1)
    Local $nID = GUICtrlCreateButton($sText, $iLeft, $iTop, $iWidth, $iHeight, $nStyle, $nExStyle)
    
    If $sIconFile = '' Then Return $nID
    
    Local $hIL = _GUIImageList_Create(16, 16, 5, BitOr($ILC_MASK, $ILC_COLOR32), 0, 1)
    
    _GUIImageList_AddIcon($hIL, $sIconFile, $nIconID)
    _GUICtrlButton_SetImageList($nID, $hIL)
    
    Return $nID
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

@Armand

you should search in help helpfile...

#include <GuiButton.au3>
$btn = GUICtrlCreateButton("", 5, 5, 26, 26, $BS_ICON)
_GUICtrlButton_SetImage($btn, 'shell32.ico', -3)

Cheers, FireFox.

And you should first read carefully what the OP is asking for, and check what you are posting :)

Your example will not work with text.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

@MrCreator

Yep, but working for picture... I dont care if its not what he wants. I just want to help him a little and if he isnt happy, he should search in helpfile...

Cheers, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Almost... but not quit what i wanted / needed...

well... I just wanted to set the background for the button and have different text shown OVER that bg whenever i want...

using that "_GUICtrlCreateButton" func only adds the image to the control... and yet it's Z-index is over the text....

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

  • Moderators

Armand,

I cannot help with text over picture, but I can offer you text AND image:

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

$mywin = GUICreate("Images amd Text on Buttons", 210, 440)

; Button 1 uses an icon - small version of 32x32 - replaces text
$btn1 = GUICtrlCreateButton("Test 1 - Test 1", 30, 30, 150, 64, $BS_ICON)
GUICtrlSetImage($btn1, "Test.ico", 1, 0)

; Button 2 uses an icon - large version of 32x32 - replaces text
$btn2 = GUICtrlCreateButton("Test 2 - Test 2", 30, 110, 150, 64, $BS_ICON)
GUICtrlSetImage($btn2, "Test.ico", 1, 1)

; Button 3 uses a bitmap - actual size - replaces text
$btn3 = GUICtrlCreateButton("Test 3 - Test 3", 30, 190, 150, 64, $BS_BITMAP)
GUICtrlSetImage($btn3, "Test.bmp")

; Buttons 4 & 5 use Valuater's UDF and place the icon where user requires - user chosen size - also shows text 
$btn4 = IconButton("Test 4 - Test 4", 30, 270, 150, 64, 16, "Test.ico")

$btn5 = IconButton("Test 5 - Test 5", 30, 350, 150, 64, 32, "Test.ico")

GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

GUIDelete()
    
Exit

; Valuater's UDF

Func IconButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $BIconSize, $BIDLL, $BIconNum = -1)
    GUICtrlCreateIcon($BIDLL, $BIconNum, $BIleft + 5, $BItop + (($BIheight - $BIconSize) / 2), $BIconSize, $BIconSize)
    GUICtrlSetState( -1, $GUI_DISABLE)
    $XS_btnx = GUICtrlCreateButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $WS_CLIPSIBLINGS)
    Return $XS_btnx
EndFunc

And again full credit to Valuater for the UDF.

All you need to do is have a .bmp and a .ico file in the same folder as this script and it will show you how the different codings work.

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

hey,

think this is what you need

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


Global $hMainGUI = GUICreate('PicButton')
Global $ahPicButton1 = _GUICtrlCreatePicButton("Button1", "picbtn.jpg", 10, 10, 75, 25) ; create our picbutton
GUICtrlSetCursor($ahPicButton1[0], 0) ; set the cursor to handpoint
GUISetState(@SW_SHOW, $hMainGUI)


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ahPicButton1[0], $ahPicButton1[1] ; check if either the label or pic was clicked
            MsgBox(64, "ImageButton", "You clicked on image button 1")
    EndSwitch

    Sleep(25)
WEnd


;================================================================================
; Function Name....: _GUICtrlCreatePicButton
; Description......: Create a pic as background with an overlaying label for the text
; Syntax...........: _GUICtrlCreatePicButton($sText, $sImg, $iLeft, $iTop[, $iWidth = Default[, $iHeight = Default]])
; Parameter(s).....: $sText - The text to write in the label of the button
;                    $sImg - The path to the image to use as the background of the button
;                    $iLeft - Distance from the left side of the gui.
;                    $iTop - Distance from the top side of the gui.
;                    $iWidth - [optional] The width of the control.
;                    $iHeight - [optional] The width of the control.
; Return Value(s)..: (Array) $aArray[0] = handle to the Pic, $aArray[1] = handle to the Label
; Requirement(s)...: -
; Related..........: - 
; Limitation(s)....: - 
; Comment(s).......: Does not work over other pic etc.
; Author(s)........: Robjong
; Modified.........: -
;================================================================================
Func _GUICtrlCreatePicButton($sText, $sImg, $iLeft, $iTop, $iWidth = Default, $iHeight = Default)
    If Not $iWidth Or $iWidth < 0 Or $iWidth == Default Then $iWidth = 75
    If Not $iHeight Or $iHeight < 0 Or $iHeight == Default Then $iHeight = 25
    
    Local $hCtrls[2] ; define an array for the controls
    $hCtrls[0] = GUICtrlCreatePic($sImg, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS)) ; create bg pic
    $hCtrls[1] = GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, BitOR($SS_NOTIFY, $SS_CENTER, $SS_CENTERIMAGE)) ; create text label ontop of the pic
    
    GUICtrlSetBkColor($hCtrls[0], $GUI_BKCOLOR_TRANSPARENT) ; set Pic bkclolor to transparent
    GUICtrlSetBkColor($hCtrls[1], $GUI_BKCOLOR_TRANSPARENT) ; set Label bkclolor to transparent
    
    Return $hCtrls ; return array with control handles
EndFunc   ;==>_GUICtrlCreatePicButton

Edit: comments + func header

Edited by Robjong
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...