---
name: "ctrlTextWidth"
type: command
status: ok
groups: ["GUI Control"]
arma3_since: "1.78"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/ctrlTextWidth
revid: 373703
updated: 2025-06-20T08:16:47Z
---

# ctrlTextWidth

*Command · GUI Control · Arma 3 v1.78*

## Description

Returns the width of the control text including left and right margins (0.008 each). Supported control [types](../commands/ctrlType.md) are:
- CT_STATIC 0
- CT_EDIT 2
- CT_STRUCTURED_TEXT 13
- Arma 3 v2.06 CT_XKEYDESC 40
- Arma 3 v2.06 CT_XBUTTON 41
- Arma 3 v2.06 CT_SHORTCUTBUTTON 16
- Arma 3 v2.06 CT_BUTTON 1
- Arma 3 v2.06 CT_ACTIVETEXT 11

> [!NOTE]
> For control-independent text width estimate see [getTextWidth](../commands/getTextWidth.md).

## Syntax

```sqf
ctrlTextWidth control
```

**Parameters:**

- `control`: [Control](../topics/Control.md)

**Returns:** [Number](../topics/Number.md)

## Examples

### Example 1

```sqf
private _w = ctrlTextWidth _ctrl;
```

## See also

[getTextWidth](../commands/getTextWidth.md) · [ctrlTextHeight](../commands/ctrlTextHeight.md) · [ctrlSetText](../commands/ctrlSetText.md) · [ctrlType](../commands/ctrlType.md) · Arma: GUI Configuration

## Community notes

**R3vo** — 2020-10-28

When working with multiline controls [ctrlTextWidth](../commands/ctrlTextWidth.md) or [getTextWidth](../commands/getTextWidth.md) will not return a proper value since the text will be treated as one long line.

**Solution (Execute in Eden Editor):**

```sqf
disableSerialization;

private _display = findDisplay 313 createDisplay "RscDisplayEmpty";

private _edit = _display ctrlCreate ["RscEditMulti", -1];
_edit ctrlSetPosition [0,0,1,1];
_edit ctrlSetBackgroundColor [0,0,0,1];
_edit ctrlSetFont "EtelkaMonospacePro";
_edit ctrlSetFontHeight 0.03;
_edit ctrlCommit 0;

private _longestLineWidth = 0;
private _exampleString = "abcdefghijklmnopqrstuvxyz0134567890";
private _text = "";

for "_lines" from 1 to 400 do // loop through all lines and find the longest one
{
    _lineText = _exampleString select [round random 35];
    _longestLineWidth = _longestLineWidth max (_lineText getTextWidth ["EtelkaMonospacePro", 0.03]);
    _text = _text + _lineText + endl;
};

_edit ctrlSetPositionW (_longestLineWidth + 2 * 0.008); // width of longest line + left and right margin set in engine
_edit ctrlCommit 0;
_edit ctrlSetText _text;
```

---

**Sa-Matra** — 2025-06-20

If you have ui2textures in the text, there is a slight change this command can return NaN if texture is bugged, can be checked with [finite](../commands/finite.md) for these rare cases.

<sub>Source: [BI Community Wiki — ctrlTextWidth](https://community.bistudio.com/wiki/ctrlTextWidth) (revision 373703).</sub>
