Nevron Open Vision Documentation
User Interface / Widgets / Buttons / Push Buttons
In This Topic
    Push Buttons
    In This Topic

    Push buttons are represented by the NButton class, which derives from NButtonBase. This is the most commonly used type of button. Typical examples are the Ok and Cancel buttons of a form or dialog as well as for other "actions" that the user may need to perform. The NButton class also contains a static method CreateImageAndText that can be used to quickly create a push button, which consists of an image and text next to it.

    The WindowResult property of the NButton can be used to associate a window result with the window, which contains the button. This is commonly used when building dialogs, like demonstrated in the following example:

    Window Result Example
    Copy Code
    void WindowResultTest()
    {
        // create OK and Cancel buttons with respective results
        // when these buttons are clicke -> we need to close the window that contains them
        NButton okButton = new NButton("OK");
        okButton.WindowResult = ENWindowResult.OK;
        okButton.Click += new Nevron.Nov.Function<NEventArgs>(OnFormButtonClick);
        NButton cancelButton = new NButton("Cancel");
        cancelButton.WindowResult = ENWindowResult.Cancel;
        cancelButton.Click += new Nevron.Nov.Function<NEventArgs>(OnFormButtonClick);
        // arrange them in a horizontal stack
        NStackPanel stack = new NStackPanel();
        stack.Direction = ENHVDirection.LeftToRight;
        stack.Add(okButton);
        stack.Add(cancelButton);
        // show a modal window that contains the stack
        NTopLevelWindow wnd = new NTopLevelWindow();
        wnd.Content = stack;
        wnd.Closed += new Nevron.Nov.Function<NEventArgs>(OnWindowClosed);
        wnd.Modal = true;
        wnd.Open();
    }
    void OnFormButtonClick(NEventArgs arg)
    {
        // close the window that contains the button
        NTopLevelWindow wnd = (NTopLevelWindow)(((NWidget)arg.TargetNode).OwnerWindow);
        wnd.Close();
    }
    void OnWindowClosed(NEventArgs arg)
    {
        if (arg.EventPhase != ENEventPhase.AtTarget)
            return;
        // inspect the window result.
        // if result is None - then the user closed the window via the control box
        // if result is OK - then the user clicked the OK button.
        // if result is Cancel - then the user clicked the Cancel button.
        NTopLevelWindow wnd = (NTopLevelWindow)arg.TargetNode;
        Console.WriteLine("Window Closed with Result" + wnd.Result);
    }