Skip to content
qPCR4vir edited this page Mar 23, 2015 · 1 revision

Inputbox provides a simple convenience dialog to get single/multiple values from the user.

using namespace nana;

form fm;    
fm.events().click([&fm]
{
    //Translate these words into Chinese.
    internationalization i18n;
    i18n.set("OK", L"确定");
    i18n.set("Cancel", L"取消");
    i18n.set("February", L"二月");

    //Define a inputbox.
    inputbox ibox(fm, L"description hello this is a long description.", L"title");

    //Define the contents what are acquired from the user.

    //Acquire an integer
    inputbox::integer integer{L"label", 15, -10, 100, 1};
    //Acquire a double
    inputbox::real real{ L"input a double value", 15, -10, 100, 1.5 };
    //Acquire a text in a specified range.
    inputbox::text text0( L"combox text", { L"Hello", L"Nana", L"C++", L"Library" } );
    //Acquire a text.
    inputbox::text text1{ L"textbox text" };
    //Acquire a date.
    inputbox::date date{L"date"};

    //Show the inputbox, and it returns true if user clicked the 'OK' button.
    if (ibox.show(integer, real, text0, text1, date))
    {
        auto n = integer.value(); //int
        auto r = real.value();    //double
        auto t1 = text0.value();  //nana::string(std::wstring)
        auto t2 = text1.value();  //nana::string
        auto d1 = date.value();   //nana::string
        auto year = date.year();  //int
        auto month = date.month(); //int
        auto day = date.day();     //int
    }
});

The inputbox provides 2 methods to show: show() and show_modal(), as the name describs, show() does not prevent the user interactions from other windows, and show_modal() blocks the user interactions with other windows until the inputbox is closed.

Clone this wiki locally