Jump to content

I can't use Button with $BS_LEFT and change backgroundcolor


Luigi
 Share

Recommended Posts

I create a simple script, with two buttons.

The first button make nothing.

The second button only change the background color of first button.

Every thing work nice... but... I need change button's color with $BS_LEFT or another style in the first button, this is the problem.

Perhaps I use a wrong style in button.

But when background color is changed, the style is missing.

And try apply the style again, the background color is missing! 8D

Try uncomment line 24 and comment it, to see.

What is going on?

I Try with $SS_LEFT and nothing is changing.

#include-once
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
Global $hGui, $hMsg
Global $color

$hGui = GUICreate('title', 140, 80)

$hButton0 = GUICtrlCreateButton('button', 10, 10, 120, 20, $BS_LEFT)
GUICtrlSetBkColor($hButton0, 0xff0000)
$hButton1 = GUICtrlCreateButton('change color', 10, 40, 120, 20)

GUISetState(@SW_SHOWNORMAL)

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            _exit()
        Case $hButton1
            $color = _Iif($color == 0x00ff00, 0xff0000, 0x00ff00)
            GUICtrlSetBkColor($hButton0, $color)
            ;GUICtrlSetStyle($hButton0, $BS_LEFT);try coment and uncoment this line, and see the error...
    EndSwitch
WEnd

Func _exit()
    Exit
EndFunc   ;==>_exit
Edited by detefon

Visit my repository

Link to comment
Share on other sites

  • Moderators

detefon,

There is a bug deep within the core AutoIt GUI code (and which will not be fixed any time soon) which means that colouring buttons leads to all sorts of problems - they trap the {ENTER} key and refuse many style changes (as you have discovered). :(

I suggest you drop the idea of coloured buttons and perhaps use a border - like this: ;)

#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
Global $hGui, $hMsg
Global $color

$hGui = GUICreate('title', 140, 80)

$cLabel = GUICtrlCreateLabel("", 8, 8, 124, 24)
GUICtrlSetBkColor($cLabel, 0xff0000)
$hButton0 = GUICtrlCreateButton('button', 10, 10, 120, 20, $BS_LEFT)

$hButton1 = GUICtrlCreateButton('change color', 10, 40, 120, 20)

GUISetState(@SW_SHOWNORMAL)

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            _exit()
        Case $hButton1
            $color = _Iif($color == 0x00ff00, 0xff0000, 0x00ff00)
            GUICtrlSetBkColor($cLabel, $color)
            GUICtrlSetStyle($hButton0, $BS_LEFT);try coment and uncoment this line, and see the error...
    EndSwitch
WEnd

Func _exit()
    Exit
EndFunc   ;==>_exit
How does that look to you? :)

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

detefon,

 

With one answer, solve two questions!

Wow, even better than normal! Glad I could help. :D

What was the second problem? :huh:

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

detefon,

Excellent, but I forgot to mention that you need to disable the label if you want the control above it to be actionable. Try this script and you will see what I mean:

#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>

Global $hGui, $hMsg
Global $color

$hGui = GUICreate('title', 140, 80)

$cLabel = GUICtrlCreateLabel("", 8, 8, 124, 24)
GUICtrlSetBkColor($cLabel, 0xff0000)
;GUICtrlSetState($cLabel, $GUI_DISABLE) ; Try with this commented and then not <<<<<<<<<<<<<<<<<<<<<
$hButton0 = GUICtrlCreateButton('button', 10, 10, 120, 20, $BS_LEFT)

$hButton1 = GUICtrlCreateButton('change color', 10, 40, 120, 20)

GUISetState(@SW_SHOWNORMAL)

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            _exit()
        Case $hButton1
            $color = _Iif($color == 0x00ff00, 0xff0000, 0x00ff00)
            GUICtrlSetBkColor($cLabel, $color)
        Case $hButton0
            MsgBox($MB_SYSTEMMODAL, "Hi", "Pressed")
    EndSwitch
WEnd

Func _exit()
    Exit
EndFunc   ;==>_exit
Sorry about that. ;)

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

Greate! The first step is ok!

But... I don't have no idea for radio item (draw a circle around).

GDIPlus? Is not a lot of power to a simple question?

Perhaps GUICtrlSetGraphic to draw a circle under the radio? Its seems a choice... Is the good choice? I can't see nothing.

Visit my repository

Link to comment
Share on other sites

Radio buttons can be colored, it's just normal buttons that can't.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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