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

    All buttons in NOV UI inherit from the abstract NButtonBase class which is a content element that provides support for a click event. The fact that the button is a content element means that it can contain every widget.

    In most cases you will create buttons by calling the initializing constructor that accepts an object parameter. The passed object is converted to a widget via the NWidget.FromObject static method. To create a button with image and text, call the static CreateImageAndText method of the NButton class. You can also create buttons by calling their default constructor and then setting their Content as demonstrated in the following code example:

    Creating Buttons
    Copy Code
    // Shortcut for creating a button with a label (internally uses NWidget.FromObject).
    NButton button1 = new NButton("Hello NOV");
    
    // Shortcut equivalent
    NButton button2 = new NButton();
    button2.Content = new NLabel("Hello NOV");
    
    // Shortcut for creating a button with image and text
    NImage image = Nevron.Nov.Presentation.NResources.Image_File_Open_png;
    NButton button3 = NButton.CreateImageAndText(image, "Open");
    

     Clicking Buttons

    All types of buttons raise a Click event. Depending on the button ClickMode, the click event is raised either when the button changes it's state from normal to pressed (ClickMode = Press), or when it changes its state from pressed or normal (i.e. is released - ClickMode = Release).

    A button can be pressed and subsequently released in two ways:

    1. Keyboard - when the user presses the Space keyboard button.
    2. Mouse - when the user presses the Left mouse button over the button.

    The example below demonstrates how to create a button and handle its click event:

    Handling the Button Click Event
    Copy Code
    NButton button = new NButton("Click me");
    button.Click += new new Function<NEventArgs>(OnButtonClick);
    
    private void OnButtonClick(NEventArgs arg1)
    {
        // Get the clicked button
        NButton button = (NButton)arg1.CurrentTargetNode;
    }
    

    Buttons expose a DoClick public method that can be used to generate a Click event for the button. This is useful when you need to simulate a click event for a button as if the user has clicked it using the mouse.

     Buttons Class Hierarchy

    The image below shows the button base descendants: