getTextExtent

getTextExtent(str: String): Integer;

The getTextExtent method of the Window class returns the width in pixels required to display the string specified in the str parameter in this window using its current font.

The string is treated as a single line, unless it contains carriage return characters, in which case this method returns the width of the longest line of the string.

The appearance of text in a table cell when setting the text width to the result of the getTextExtent method may not produce the result that you require, as pixels are required for grid lines and spacing.

The method in the following example shows the use of the getTextExtent method.

listBoxSource_mouseDown(listbox:        ListBox input;
                        button, shift:  Integer;
                        x, y:           Real) updating;
vars
    count : Integer;
begin
    wantToCopy := false;
    if listBoxSource.listCount >= 1 then
        listBoxSource.itemSelected[listBoxSource.listIndex] := true;
        mousedown := true;
        foreach count in 1 to listbox.listCount do
            if listbox.itemSelected[count] <> true then
                listbox.itemEnabled[count] := false;
            endif;
        endforeach;
        frameDisplay.width := listBoxSource.text.length *
                    getTextExtent("*");
        drawInfo(x, y, listBoxSource.text);
        frameDisplay.visible := true;
        transfer := listBoxSource.itemObject[listBoxSource.listIndex].Fault;
        if shift.bitAnd(2) = 2 then
            wantToCopy := true;
        endif;
    endif;
end;