{"name":"ctrlAddEventHandler","title":"ctrlAddEventHandler","type":"command","url":"https://community.bistudio.com/wiki/ctrlAddEventHandler","revid":379288,"updated":"2026-10-30T23:46:34Z","groups":["GUI Control - Event Handlers","Event Handlers"],"status":"ok","games":{"arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma2 1.00","arma3_since":"0.50","description":"Add an event handler to the given control.\n\n> [!IMPORTANT]\n> - 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.\n> - When using the event names listed here with the ctrlAddEventHandler, ctrlSetEventHandler, displayAddEventHandler or displaySetEventHandler commands, the prefix \"on\" in the event name must be removed (e.g. '**ButtonDown'** instead of '**onButtonDown'**).","syntaxes":[{"syntax":"control ctrlAddEventHandler [handler, function]","params":[{"name":"control","type":"Control","type_expr":"Control"},{"name":"handler","type":"String","description":"handler name, see User Interface Event Handlers","type_expr":"String"},{"name":"function","type":"String or Arma 3 v1.06 Code","description":"script. Several Magic Variables are available:\n\n- Event Handler parameters are accessible via `_this`\n- The Event Handler type is available as `_thisEvent`\n- The Event Handler index is available as `_thisEventHandler`","type_expr":"String | Code"}],"returns":{"type":"Number","type_expr":"Number","description":"handler ID or -1 if failed"},"form":"binary","left":{"text":"control"},"right":{"text":"[handler, function]"}}],"examples":[{"code":["_map ctrlAddEventHandler [\"Draw\", \"_this call BIS_fnc_strategicMapOpen_draw\"];"]},{"code":["_map ctrlAddEventHandler [\"Draw\", { hintSilent str _this }];"]},{"code":["findDisplay 12 displayCtrl 51 ctrlAddEventHandler [\"Draw\", { hintSilent str _this }]; //Arma 3 map control"]}],"see_also":["displayAddEventHandler","ctrlRemoveEventHandler","ctrlRemoveAllEventHandlers"]}