Jump to content
Sign in to follow this  

right Align button text

Recommended Posts



I have a really weird problem with creating buttons on a GUI. I want to right align text on the edit buttons ($Editbutton[]), but somehow it's not working and the text is centered.

When I create a test button outside of the for/next loop ($Testbutton), the button text is right aligned correctly!?

Below is this section of the code. Does anyone have a clue what causes this behaviour? Many thanks in advance!

$Testbutton = GUICtrlCreateButton("TEST", 0, 0 , 150, 30, $BS_RIGHT)
    For $file_count = 1 To $NumOfFiles - 2 Step 1
        If $config_file[$file_count] <> "NotFound" Then
            $Editbutton[$file_count] = GUICtrlCreateButton($config_filevar[$file_count] & $config_file[$file_count], 40, 170 + (44 * ($file_count - 1)), 320, 30, $BS_RIGHT)
            GUICtrlSetTip(-1,$config_filevar[$file_count] & $config_file[$file_count])
            GUICtrlSetBkColor(-1, $DefaultBackgroundColour)
            GUICtrlSetColor(-1, $DefaultTextColour)
            $Editbuttonindex[$file_count] = GUICtrlCreateButton("&" & $file_count, 10, 170 + (44 * ($file_count - 1)), 25, 30, $BS_FLAT)
            GUICtrlSetBkColor(-1, $DefaultBackgroundColour)
            GUICtrlSetColor(-1, $DefaultTextColour)

Share this post

Link to post
Share on other sites


As soon as you colour the $Editbutton[] buttons you loose all text formatting. This is a longterm bug which cannot be fixed without rewriting the base GUI code - and therefore never will be in AutoIt 3. ;)

Solution: Do not colour buttons, or do not use aligned text. :P

Sorry not to be more helpful - to make up for it here are 2 tips: :blink:

- 1. There is usually no point in using the $BS_FLAT style unless you remove any themes on the button like this:

$hButton = GUICtrlCreateButton("Button", 10, 50, 80, 30)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($hButton), "wstr", 0, "wstr", 0)
GUICtrlSetStyle($hButton, $BS_FLAT)

- 2. I am not sure if you are using the "&" on the $Editbuttonindex[] buttons to set the accelerator keys or not. If you are - then you are doing it correctly. If you actually wanted the "&" to appear on the button, you need to double it like this:

$Editbuttonindex[$file_count] = GUICtrlCreateButton("&&" & $file_count, 10, 170 + (44 * ($file_count - 1)), 25, 30)

So it might only be the one tip after all! :


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:


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


Share this post

Link to post
Share on other sites


Thank you very much for the answer! This was starting to drive me mad ... :blink:!

Also thank you for the tips:

1) I have been playing with styles on the buttons and forgot to remove the $BS_FLAT. It shows them in '3D' style now, which is actually what I always wanted :-)

Nevertheless I didn't know about what you wrote.

2) The '&' On the button is to set accelerator key, so it is correct the way it is.

Best regards,


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
Sign in to follow this