Nevron Open Vision Documentation
User Interface / Widgets / Context Popups / Interactive Context Popup
In This Topic
    Interactive Context Popup
    In This Topic

    NOV can show not only drop down menus, but any widget in a context fashion. The example below demonstrates how you can display an interactive popup that allows the user enter some text and if the user clicks on the <OK> button, the newly entered text is applied on the label for which we show the context popup:

    Interactive Context Popup Example
    Copy Code
    NLabel label = new NLabel("Right click me to change my text");
    label.HorizontalPlacement = ENHorizontalPlacement.Left;
    label.VerticalPlacement = ENVerticalPlacement.Top;
    label.Background = new NBackground(NColor.PapayaWhip);
    label.Border = NBorder.CreateFilledBorder(NColor.Black);
    label.BorderThickness = new NMargins(1);
    label.MouseDown += new new Function<NMouseButtonEventArgs>(OnLabelMouseDown);
    
    private void OnLabelMouseDown(NMouseButtonEventArgs arg1)
    {
        // Check whether the right mose down was used
        if (arg1.Button != ENMouseButtons.Right)
            return;
     
        // Mark the event as handled
        arg1.Cancel = true;
     
        // Create the content of the popup
        NStackPanel stack = new NStackPanel();
        stack.Padding = new NMargins(5);
        NLabel label = new NLabel("New text:");
        NTextBox textBox = new NTextBox();
        textBox.PreferredWidth = 200;
        NPairBox pairBox = new NPairBox(label, textBox);
        stack.Add(pairBox);
     
        NButtonStrip buttonStrip = new NButtonStrip();
        buttonStrip.InitOKCancelButtonStrip();
        stack.Add(buttonStrip);
     
        // Create the popup window
        NPopupWindow popup = new NPopupWindow(stack);
       
        // Store the label in the tag property of the popup
        popup.Tag = args.CurrentTarget;
     
        // Subscribe to the window's closed event
        popup.Closed += new Function<NEventArgs>(OnPopupClosed);
     
        // Open the popup window in context fashion
        NPopupWindow.OpenInContext(popup, arg1.CurrentTargetNode, arg1.ScreenPosition);
    }
    private void OnPopupClosed(NEventArgs arg1)
    {
        NPopupWindow popup = (NPopupWindow)arg1.CurrentTargetNode;
        if (popup.Result != ENWindowResult.OK)
            return;
     
        // Get the popup's text box
        NStackPanel stack = (NStackPanel)popup.Content;
        NPairBox pairBox = (NPairBox)stack[0];
        NTextBox textBox = (NTextBox)pairBox.Box2;
     
        // Update the text of the label
        NLabel label = (NLabel)popup.Tag;
        label.Text = textBox.Text;
    }
    

    See Also