User71

Button Colour and Style

7 posts in this topic

Hi All,

I'm sure this is a simple one to answer and I have searched and experimented before I asked (well enough hopefully!)

I'm trying to set a button background to be white, the font colour red, centred vertically and horizontally and multi-line. Can it be done?

Here is my example code:

#include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstantS.au3>
#include <FontConstants.au3>
#include "ColorConstants.au3"

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("GUI", 250, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Button = GUICtrlCreateButton("Button" & @CRLF & "One", 160, 185, 85, 110, BitOR($BS_MULTILINE, $BS_CENTER, $BS_VCENTER, $WS_EX_WINDOWEDGE))
GUICtrlSetBkColor(-1, $COLOR_White)
GUICtrlSetFont($Button, 14, 800, 0, "MV Boli", 5)
GUICtrlSetColor($Button, 0xFF0000)
GUICtrlSetOnEvent($Button, "_Exit")
GUISetState()

While 1
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

With everything I have tried, this is the closest I get, button white, font red, correct font, but no centring and sometimes no multi-line (depending on button text and font size). I saw I might have to add the default button forced style back in so I did that too $WS_EX_WindowEdge.

Thanks for any help and apologies if I've missed an obvious answer to this elsewhere.

Share this post


Link to post
Share on other sites



This works for me.

#include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstantS.au3>
#include <FontConstants.au3>
#include "ColorConstants.au3"

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("GUI", 250, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Button = GUICtrlCreateButton("Button" & @CRLF & "One", 160, 185, 85, 110, BitOR($SS_CENTER, $SS_CENTERIMAGE)) ; $BS_MULTILINE, $BS_CENTER, $BS_VCENTER, $WS_EX_WINDOWEDGE))
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetFont($Button, 14, 800, 0, "MV Boli", 5)
GUICtrlSetColor($Button, 0xFF0000)
GUICtrlSetOnEvent($Button, "_Exit")

GUISetState()

While 1
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 


MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites

Thanks Reb, tried your code and it centres it but no multi-line, and if I put multi-line on the end it centres it at the top instead and it ignores the @CRLF in the text. Did I do something wrong?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I guess you could always fake a button with a label.

 

include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstantS.au3>
#include <FontConstants.au3>
#include "ColorConstants.au3"

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("GUI", 250, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$bBm = "Button" & @CRLF & "One"
$Button = GUICtrlCreateLabel(@CRLF & $bBm, 160, 185, 85, 110, BitOR($SS_CENTER, $BS_VCENTER),$WS_EX_CLIENTEDGE) ;, $SS_CENTERIMAGE)) ; $BS_MULTILINE, $BS_CENTER, $BS_VCENTER, $WS_EX_WINDOWEDGE))
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetFont($Button, 14, 800, 0, "MV Boli", 5)
GUICtrlSetColor($Button, 0xFF0000)
GUICtrlSetOnEvent($Button, "_Exit")

GUISetState()

While 1
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

_WinAPI_DrawText

 

Edited by reb
Removed unused #include

MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites

reb, you're using $ss_* styles in a button control, $ss_* styles are for static controls, labels/icons/images. There is no button control constant that has the same value as $ss_center or $ss_centerimage (although there is a constant with the same value as _centerimage, it's used in a checkbox control), so there's no telling what either of those settings might produce as a result if anything. 

I've tried every combination of button style setting and I have not been able to produce a button with multiline and vertically centered text. The best I could come up with was to add a @CRLF in front of the button text to get it to add another line above the text.

 


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

Share this post


Link to post
Share on other sites

@ BrewManNH

I revised my post just above yours using label constants.  I see your point.

Thank you.

#include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstantS.au3>
#include <FontConstants.au3>
#include "ColorConstants.au3"

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("GUI", 250, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$bBm = "Button" & @CRLF & "One"
$Button = GUICtrlCreateLabel(@CRLF & $bBm, 160, 185, 85, 110, $SS_CENTER,$WS_EX_CLIENTEDGE) ;, $SS_CENTERIMAGE)) ; $BS_MULTILINE, $BS_CENTER, $BS_VCENTER, $WS_EX_WINDOWEDGE))
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetFont($Button, 14, 800, 0, "MV Boli", 5)
GUICtrlSetColor($Button, 0xFF0000)
GUICtrlSetOnEvent($Button, "_Exit")

GUISetState()

While 1
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

.


MEASURE TWICE - CUT ONCE

Share this post


Link to post
Share on other sites

Thank you both for your answers, I didn't even think of adding a @CRLF before the text! Unless anyone else can tell me (us) where we're going wrong I guess it's just one of those things I'll have to work around. Anyone else?

Share this post


Link to post
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

  • Similar Content

    • Skysnake
      By Skysnake
      My code.
      Does not work
      ;~ [optional] Control styles: ;~ $ES_AUTOHSCROLL - Automatically scrolls text to the right by 10 characters when the user types a character at the end of the line. ;~ $ES_AUTOVSCROLL - Automatically scrolls text up one page when the user presses the ENTER key on the last line. Local $hEditNewText = _GUICtrlEdit_Create($hGUI, "This is a test" & @CRLF & "Another Line", 8, 500, 715, 100) Local $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_STYLE) ; get style Local $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_EXSTYLE) ; get extended style ;GUICtrlSetStyle($hEditNewText, BitXOR($iStyle, $ES_AUTOHSCROLL)) ; remove hscroll left to right (force wrap) GUICtrlSetStyle($hEditNewText, BitAND($iStyle, BitNOT($ES_AUTOHSCROLL))) https://www.autoitscript.com/wiki/Setting_Styles
      Also tried this
      ;~ https://www.autoitscript.com/forum/topic/113598-solved-scrolling-read-only-text-display-using-edit-not-input-control/ Local $hEditNewText = GUICtrlCreateEdit("This is a test" & @CRLF & "Another Line", 8, 500, 715, 100) Local $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_STYLE) ; get style Local $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($hEditNewText), $GWL_EXSTYLE) ; get extended style GUICtrlSetStyle($hEditNewText, BitAND($iStyle, BitNOT($ES_AUTOHSCROLL)))  
      However, this works:
      Local $hEditNewText = GUICtrlCreateEdit("This is a test" & @CRLF & "Another Line", 8, 500, 715, 100, $ES_WANTRETURN + $WS_VSCROLL + $ES_AUTOVSCROLL + $ES_MULTILINE + $WS_TABSTOP) My question stands. How to change the STYLE of an EDIT control?
      Skysnake
    • trescon
      By trescon
      Good evening, I need to configure a graphical interface where the contents of some "Button" are taken from a file I have foreseen to include with "#include".
      For the text no problem, the problem comes when I'm going to assign the color to the background of the "Button", the "Button" becomes BLACK WHITE.
      I included in the included file as follows:
      $ Promotion_Color = "$ Color_Red"
      Clarity I also imported #include the library <ColorConstants.au3>
      In the main program I wrote like this:
      $ Promotion = GUICtrlCreateButton ($ Promotion, Dim_Fin_X + $ 170, $ Dim_Fin_Y, 750.120)
      GUICtrlSetFont (-1, 70, 800, 0, "Calibri")
      GUICtrlSetBkColor ($ Promotion, $ Promotion_Color); will change background color
      I thank all those who want to help me
      Alberto
    • thoms
      By thoms
      Hello Forum,
      As said in the title, I'm searching a way to disable all tabstops in a GUI. My GUI includes 15 buttons and 3 edit controls.
      My questions:
      - is there a way to disable all tabstops at a time
      - is there a way to list all controls of a GUI and then disable tabstops one by one
      - or should I use the following line after each button creation:
      _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE, BitAND(_WinAPI_GetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE), BitNOT($WS_TABSTOP))) Thanks in advance for your valuable help!
      Thoms
      Edit: or maybe disable TAB key? I don't remember how to do!
    • AppSoftwareVld
      By AppSoftwareVld
      Hello,
       
      I need this for a project and I don't find a method for the next problem.
      I want when I click a button to create a variable ("$variable1") so if I press one more time to create one more ("$variable2") and create more and more how many times you press the button.
       
      Do you have an idea ? 
      Thank you for your attention !
    • rte7
      By rte7
      Hello. We work with the BMC Remedy site to manage incidents and would like to automate the processes of clicking through this button code:
      <a href="javascript:" class="btn btn3d menu" style="top:21; left:184; width:21; height:21;"> <img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="menu category issue" title=""> </a> I use firefox with mozrepl and autoit with include FF.au3
      I need your help
      I read the topic https://www.autoitscript.com/forum/topic/95595-ffau3-v0601b-10/ but I could not run the code from the listed commands
      ...
      It is necessary to press the button and from the list of the menu of cahorsations to select the item = "zone of trust abonent"
      Screen # 1 http://joxi.ru/52aJK7bh4a7ypA or below.
      1) Press button
      <a href="javascript:" class="btn btn3d menu" style="top:21; left:184; width:21; height:21;"> <img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="menu category issue" title=""> </a>
      2) After pressing the button, I need to choose in this menu of 4 items to select an item called "zone of trust abonent", Screen # 2 - http://joxi.ru/p27gwQKHo71VQ2
      html code table items
      <table class="MenuTable" cellpadding="0" cellspacing="0" style="width: 179px;"> <tbody class="MenuTableBody"> <tr class="MenuTableRow"> <td class="MenuEntryName" nowrap="">zone of trust abonent</td> <td class="MenuEntryNoSub" arvalue="zone of trust abonent"></td> </tr> <tr class="MenuTableRow"><td class="MenuEntryName" nowrap="">zone of trust operator</td> <td class="MenuEntryNoSub" arvalue="zone of trust operator"></td> </tr> <tr class="MenuTableRow"><td class="MenuEntryName" nowrap="">zone of trust third operator</td> <td class="MenuEntryNoSub" arvalue="zone of trust third operator"></td></tr> <tr class="MenuTableRow"><td class="MenuEntryNameHover" nowrap="">No settings</td> <td class="MenuEntryNoSubHover" arvalue="No settings"></td> </tr> </tbody> </table>
       
       
      More in detail, I choose from the menu item "zone of trust abonent" Screen # 3 - http://joxi.ru/GrqVq4ZIQEPW4m

       
      3) The choice is made, Screen # 4 http://joxi.ru/v297w6aC3PovLr
      <textarea class="text sr " wrap="off" id="arid_WIN_0_1000002488" cols="20" maxlen="60" style="top:21; left:0; width:179; height:21;" armenu="CFG:PRC:CategoryHPD-Res-T1-Q" mstyle="2" arautoc="1" arautocmb="1" arautocak="0" arautoctt="400" rows="1"> </textarea>
       
      It's all. I would be very grateful to you =) !!!!!!!!!!
      Here are more detailed codes in the attachment. 
      button1.txt
      menu - table.txt
      all.txt