Fritterandwaste Posted August 14, 2022 Posted August 14, 2022 Hi I am new to Autoit and to the forum. I'm wondering how to change the font of individual controls. In the code below, the first 3 lines work fine but the remainder do not. The ListBox and Edit controls are presented on screen but appear to adopt a default (small) font. They do not adopt the font defined by the GUISetFont and, when lines 5 and 7 are introduced, this has no effect either. The labels seem to work OK. I have also tried using the handles of the specific controls in the GUICtrlSetFont statements instead of -1 with no joy. GUISetFont(12, $FW_NORMAL, $GUI_FONTUNDER, $sFont,$hGUI) ; will display underlined characters GUICtrlCreateLabel("underlined label", 10, 20) GUICtrlCreateLabel("Hello world! How are you?", 30, 10) Local $gLbxPlayList = _GUICtrlListBox_Create($hGUI, "Play List", 100, 100, 396, 296, $LBS_STANDARD + $WS_VSCROLL) GUICtrlSetFont(-1, 12) Local $gTxtPlayList = _GUICtrlEdit_Create($hGUI, "Edit this", 100, 500, 100, 50) GUICtrlSetFont(-1, 12) What might I be doing wrong please?
Solution Fritterandwaste Posted August 14, 2022 Author Solution Posted August 14, 2022 Ah, it's not possible using GUICtrlSetFont but this post resolves it. It's odd that the documentation does not make this clear.
Moderators Melba23 Posted August 15, 2022 Moderators Posted August 15, 2022 Fritterandwaste, The reason that the GUICtrlSetFont command does not work on the _GUICtrlEdit_Create command is because there is a fundamental difference between "native" AutoIt controls (those created using a GUICtrlCreate***** command) and those created with the UDF libraries (usually in the form of a GUICtrl*****_Create command). The former are managed within AutoIt and the return from the creation command is a ControlID - which is actually an index to an internal array maintained by AutoIt. So when this index is passed to one of the "native" commands (such as GUICtrlSetFont) AutoIt know which control in the array is to be amended. UDF commands are passed direct to Windows and return a "Windows handle" - an ID used by Windows itself to identify everything (and I mean everything) on the system. So passing a "handle" to a command expecting a "ControlID", or vice versa, will not work. The docs do mention this - here are some examples where the ControlID/handle usage is explicitly mentioned: For "native" controls: GUICtrlCreateLabel: Return Value Success: the identifier (controlID) of the new control. GUICtrlSetFont: Parameters controlID The control identifier (controlID) as returned by a GUICtrlCreate...() function, or -1 for the last created control. For UDF controls: _GUICtrlListBox_Create Return Value Success: the handle to the Listbox control _GUICtrlListBox_GetText (as an example) Parameters $hWnd Control ID/Handle to the control As you can see, in the UDF case AutoIt will actually allow the passing of a "ControlID" as it stores the corresponding handle in its internal array - obviously the reverse cannot work as Windows has no knowledge of the internal array within AutoIt. I hope that helps. 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
Fritterandwaste Posted September 18, 2022 Author Posted September 18, 2022 Thank you for your replies and so sorry for the long delay. I have been away. I think I've got it now!
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