Zest Posted July 9, 2010 Posted July 9, 2010 Hello, 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) EndIf Next
Moderators Melba23 Posted July 9, 2010 Moderators Posted July 9, 2010 Zest,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. Sorry not to be more helpful - to make up for it here are 2 tips: - 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! 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
Zest Posted July 9, 2010 Author Posted July 9, 2010 @Melba23 Thank you very much for the answer! This was starting to drive me mad ... ! 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, Wouter
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