How To: Create a Message Box Flyout With User Control

  • 4 minutes to read

The How To: Create a Modal Message Box Flyout and How To: Create a Pop-up Flyout examples demonstrate how to add a Flyout that contains either a Document or a FlyoutAction. In this example, the Flyout contains both a Document and an Action. Such Flyouts are designed to display complex message boxes with user controls and custom buttons.

  1. Create a new WindowsUI View application or open an existing one.
  2. Open the DocumentManager's context menu and run the Designer.

    DocumentManager - Designer Windows

  3. Switch to the 'Elements' section and select 'Content Containers'. Click the 'Add New Container' button and choose 'Flyout' from the drop-down list.

    Flyouts - adding new flyout

  4. Select the newly created Flyout and change its name to userConrolFlyout via the property grid.
  5. In the Visual Studio Solution Explorer window, right click your project and select 'Add', then 'Add New Item' and choose a User Control. Change its name to ucAddCustomer and click 'OK'. Add four text boxes and labels onto your user control as shown below:

    Flyouts - ucAddCustomer

  6. Switch back to the Document Manager Designer. Open the 'Elements' section, choose 'Documents' and click the 'Populate' button. A document for your user control will be created automatically. Change its name to addCustomerDocument. Note that a corresponding Tile appears as well. You can remove it in the 'Elements' - 'Tiles' section.
  7. Call the BaseView.AddDocument method and pass a new ucAddCustomer class instance to this method as a parameter. See the Documents topic for more info.

    
    public Form1() {
        InitializeComponent();
        windowsUIView1.AddDocument(new ucAddCustomer());
        . . .
    }
    
  8. Now pass the created user control to the Flyout. To do so, assign the addCustomerDocument object to the Flyout.Document property.

    Flyouts - assign the addCustomerDocument

    
    userControlFlyout.Document = addCustomerDocument;
    
  9. Add a WindowsUI button to your start-up Content Container. See the WindowsUI Buttons topic for more info.

    Flyouts - add Win8UI Button

  10. Next, handle the Content Container's BaseContentContainer.ButtonClick event. Use the WindowsUIView.ActivateContainer method to display the Flyout.

    
    private void tileContainer1_ButtonClick(object sender, DevExpress.XtraBars.Docking2010.ButtonEventArgs e) {
        windowsUIView1.ActivateContainer(userControlFlyout);
    }
    
  11. Launch your application and click the WindowsUI Button. The result should be similar to the following:

    Flyouts - document without action

    As you can see, even if the IFlyoutDefaultProperties.Style property value equals FlyoutStyle.MessageBox, the Flyout is displayed as a pop-up. This occurs because no message box buttons were specified. The easiest way to add message box buttons is to use standard button sets via the Flyout.FlyoutButtons property. Set this property to YesNo and see the result.

    Flyouts - document with standard buttons

    
    userControlFlyout.FlyoutButtons = MessageBoxButtons.YesNo;
    

    Note that you may want something more flexible than standard button sets. In this example, 'Yes' and 'No' buttons do not perfectly fit the displayed content. In this case, use FlyoutActions.

  12. Create a FlyoutAction and specify its UIActionPropertiesCore.Caption. Add a standard 'Cancel' button to its FlyoutAction.Commands collection.

    
    FlyoutAction addCustomerAction = new FlyoutAction() { Caption = "Add new customer"};
    public Form1() {
        InitializeComponent();
        . . .
        addCustomerAction.Commands.Add(FlyoutCommand.Cancel);
    }
    
  13. Add your own custom button by creating a FlyoutCommand class descendant, and overriding the required properties.

    
    class AddCommand : FlyoutCommand {
        public override string Text {
            get {
                return "Add";
            }
        }
        public override DialogResult Result {
            get {
                return DialogResult.OK;
            }
        }
    }
    
  14. Now you can add your custom button to the FlyoutAction.

    
    addCustomerAction.Commands.Add(new AddCommand());
    

    The last step is to assign your action to the Flyout via the Flyout.Action property.

    
    userControlFlyout.Action = addCustomerAction;
    
  15. Launch your application to view the results:

    Flyouts - document with custom buttons

  16. To get which Flyout Button an end-user has clicked, handle the WindowsUIView.FlyoutHidden event.

    
    private void windowsUIView1_FlyoutHidden(object sender, DevExpress.XtraBars.Docking2010.Views.WindowsUI.FlyoutResultEventArgs e) {
        if(e.Result == System.Windows.Forms.DialogResult.Yes) . . .;
        else . . .;
    }