1# Message box (lv_msgbox) 2 3## Overview 4The Message boxes act as pop-ups. 5They are built from a background container, a title, an optional close button, a text and optional buttons. 6 7The text will be broken into multiple lines automatically and the height will be set automatically to include the text and the buttons. 8 9The message box can be modal (blocking clicks on the rest of the screen) or not modal. 10 11## Parts and Styles 12The message box is built from other widgets, so you can check these widgets' documentation for details. 13- Background: [lv_obj](/widgets/obj) 14- Close button: [lv_btn](/widgets/core/btn) 15- Title and text: [lv_label](/widgets/core/label) 16- Buttons: [lv_btnmatrix](/widgets/core/btnmatrix) 17 18## Usage 19 20### Create a message box 21 22`lv_msgbox_create(parent, title, txt, btn_txts[], add_close_btn)` creates a message box. 23 24If `parent` is `NULL` the message box will be modal. `title` and `txt` are strings for the title and the text. 25`btn_txts[]` is an array with the buttons' text. E.g. `const char * btn_txts[] = {"Ok", "Cancel", NULL}`. 26`add_close_btn` can be `true` or `false` to add/don't add a close button. 27 28### Get the parts 29The building blocks of the message box can be obtained using the following functions: 30```c 31lv_obj_t * lv_msgbox_get_title(lv_obj_t * mbox); 32lv_obj_t * lv_msgbox_get_close_btn(lv_obj_t * mbox); 33lv_obj_t * lv_msgbox_get_text(lv_obj_t * mbox); 34lv_obj_t * lv_msgbox_get_btns(lv_obj_t * mbox); 35``` 36 37### Close the message box 38`lv_msgbox_close(msgbox)` closes (deletes) the message box. 39 40## Events 41- `LV_EVENT_VALUE_CHANGED` is sent by the buttons if one of them is clicked. `LV_OBJ_FLAG_EVENT_BUBBLE` is enabled on the buttons so you can add events to the message box itself. 42In the event handler, `lv_event_get_target(e)` will return the button matrix and `lv_event_get_current_target(e)` will return the message box. `lv_msgbox_get_active_btn(msgbox)` and `lv_msgbox_get_active_btn_text(msgbox)` can be used to get the index and text of the clicked button. 43 44Learn more about [Events](/overview/event). 45 46## Keys 47Keys have effect on the close button and button matrix. You can add them manually to a group if required. 48 49Learn more about [Keys](/overview/indev). 50 51 52## Example 53 54```eval_rst 55 56.. include:: ../../../examples/widgets/msgbox/index.rst 57 58``` 59 60## API 61 62```eval_rst 63 64.. doxygenfile:: lv_msgbox.h 65 :project: lvgl 66 67``` 68