---
name: "ctrlAddEventHandler"
type: command
status: ok
groups: ["GUI Control - Event Handlers", "Event Handlers"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/ctrlAddEventHandler
revid: 376337
updated: 2025-10-07T13:17:20Z
---

# ctrlAddEventHandler

*Command · GUI Control - Event Handlers, Event Handlers · Arma 3 v0.50 · introduced in Arma 2 v1.00*

## Description

Add an event handler to the given control.

> [!IMPORTANT]
> - Control event handlers are processed in reversed order, i.e. last added: first, first added: last. So if you have an override it should be set up in the 1st added EH.
> - When using the event names listed [here](../topics/User_Interface_Event_Handlers.md) with the [ctrlAddEventHandler](../commands/ctrlAddEventHandler.md), [ctrlSetEventHandler](../commands/ctrlSetEventHandler.md), [displayAddEventHandler](../commands/displayAddEventHandler.md) or [displaySetEventHandler](../commands/displaySetEventHandler.md) commands, the prefix "on" in the event name must be removed (e.g. **'ButtonDown**' instead of **'onButtonDown**').

## Syntax

```sqf
control ctrlAddEventHandler [handler, function]
```

**Parameters:**

- `control`: [Control](../topics/Control.md)
- `handler`: [String](../topics/String.md) - handler name, see [User Interface Event Handlers](../topics/User_Interface_Event_Handlers.md)
- `function`: [String](../topics/String.md), since Arma 3 v1.06 also [Code](../topics/Code.md) - script. Several [Magic Variables](../topics/Magic_Variables.md) are available:
  - Event Handler parameters are accessible via `_this`
  - The Event Handler type is available as `_thisEvent`
  - The Event Handler index is available as `_thisEventHandler`

**Returns:** [Number](../topics/Number.md) - handler ID or -1 if failed

## Examples

### Example 1

```sqf
_map ctrlAddEventHandler ["Draw", "_this call BIS_fnc_strategicMapOpen_draw"];
```

### Example 2

```sqf
_map ctrlAddEventHandler ["Draw", { hintSilent str _this }];
```

### Example 3

```sqf
findDisplay 12 displayCtrl 51 ctrlAddEventHandler ["Draw", { hintSilent str _this }]; //Arma 3 map control
```

## See also

[displayAddEventHandler](../commands/displayAddEventHandler.md) · [ctrlRemoveEventHandler](../commands/ctrlRemoveEventHandler.md) · [ctrlRemoveAllEventHandlers](../commands/ctrlRemoveAllEventHandlers.md)

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