Jump to content

Changing font of ListBox or Edit Controls

Go to solution Solved by Fritterandwaste,

Recommended Posts


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?

Link to comment
Share on other sites

  • Moderators


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:


Return Value
Success: the identifier (controlID) of the new control. 


controlID The control identifier (controlID) as returned by a GUICtrlCreate...() function, or -1 for the last created control.

For UDF controls:

Return Value
Success: the handle to the Listbox control

_GUICtrlListBox_GetText (as an example)

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


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


Link to comment
Share on other sites

  • 1 month later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...