Version

UltraPopupControlContainer Class

Component for displaying a control in a popup window.
Syntax
'Declaration
 
Public Class UltraPopupControlContainer 
   Inherits Infragistics.Win.UltraStylableComponent
   Implements Infragistics.Shared.IUltraComponent, Infragistics.Win.AppStyling.ISupportAppStyling, Infragistics.Win.IDropDownResizeHandleOwner, Infragistics.Win.IPopupItem, Infragistics.Win.IPopupItemProvider 
public class UltraPopupControlContainer : Infragistics.Win.UltraStylableComponent, Infragistics.Shared.IUltraComponent, Infragistics.Win.AppStyling.ISupportAppStyling, Infragistics.Win.IDropDownResizeHandleOwner, Infragistics.Win.IPopupItem, Infragistics.Win.IPopupItemProvider  
Remarks

The UltraPopupControlContainer is a component that can be used to display any System.Windows.Forms.Control derived class in a separate popup window. The PopupControl property is used to indicate which control should be displayed in the popup window.

The Show method can be used to display the popup window. There are several overloads of the method so that the position of the popup can be controlled. The Close method may be used to hide the popup window.

The FromControl member is a static method that may be used to obtain a reference to the UltraPopupControlContainer that is currently displaying the specified control.

The class exposes several events to provide a notification when the popup window is opening (Opening and Opened) and closed (Closed).

Example
The following sample demonstrates displaying a treeview in a popup window using the UltraPopupControlContainer component.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.Misc

Private Sub ultraPopupControlContainer1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles ultraPopupControlContainer1.Closed
    ' The Closed event is invoked when the
    ' popup has been closed and can be used to 
    ' destroy the control, perform an action, etc.

    System.Diagnostics.Debug.WriteLine("Closed")
End Sub

Private Sub ultraPopupControlContainer1_Opened(ByVal sender As Object, ByVal e As System.EventArgs) Handles ultraPopupControlContainer1.Opened
    ' The Opened event is invoked after the popup 
    ' has been displayed and can be used to further 
    ' initialize the popup

    ' For example, you can set focus to the control it displayed
    '
    Dim popup As UltraPopupControlContainer = CType(sender, UltraPopupControlContainer)

    ' the control that will be displayed can be initialized here
    If Not popup.PopupControl.ContainsFocus Then
        popup.PopupControl.Focus()
    End If
End Sub

Private Sub ultraPopupControlContainer1_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ultraPopupControlContainer1.Opening
    Dim popup As UltraPopupControlContainer = CType(sender, UltraPopupControlContainer)

    Dim tree As TreeView = Me.treeList

    ' the control that will be displayed can be initialized here
    If Not popup.PopupControl Is tree Then
        popup.PopupControl = tree
    End If

    ' this Opening event will normally be used to initialize
    ' the control that will be dropped down
    Me.InitializeDropDownTree(tree)
End Sub

Private Sub InitializeDropDownTree(ByVal tree As TreeView)
    ' initialize the tree that we will be dropping down
    ' clear any existing nodes
    tree.Nodes.Clear()

    ' allow for full row selection
    tree.FullRowSelect = True
    tree.ShowLines = False
    tree.ShowRootLines = False

    ' only show a single border
    tree.BorderStyle = BorderStyle.FixedSingle

    ' create the nodes
    tree.Nodes.Add("New")
    tree.Nodes.Add("Open Existing")
    tree.Nodes.Add("Open Recent")

    ' select the first node
    tree.SelectedNode = tree.Nodes(0)

    ' size the control so it shows all the nodes
    Dim top As Integer = tree.Nodes(0).Bounds.Top
    Dim bottom As Integer = tree.Nodes(tree.Nodes.Count - 1).Bounds.Bottom
    tree.ClientSize = New Size(tree.ClientSize.Width, bottom - top)
End Sub

Private Sub treeList_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles treeList.KeyDown
    ' when the enter key is pressed invoke
    ' the tree's Click event
    If e.KeyCode = Keys.Return Then
        Me.InvokeOnClick(Me.treeList, EventArgs.Empty)
    ElseIf e.KeyCode = Keys.Escape Then
        ' then get the popup control container that is
        ' displaying the tree and close it
        Dim popup As UltraPopupControlContainer = UltraPopupControlContainer.FromControl(CType(sender, Control))

        If Not popup Is Nothing Then
            popup.Close()
        End If
    End If
End Sub

Private Sub treeList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles treeList.Click
    Dim tree As TreeView = CType(sender, TreeView)

    ' get the selected node and perform some action on it
    Dim node As TreeNode = tree.SelectedNode

    System.Diagnostics.Debug.WriteLine("Node Clicked:" + node.Text)

    ' then get the popup control container that is
    ' displaying the tree and close it
    Dim popup As UltraPopupControlContainer = UltraPopupControlContainer.FromControl(tree)

    If Not popup Is Nothing Then
        popup.Close()
    End If
End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.Misc;

private void ultraPopupControlContainer1_Closed(object sender, System.EventArgs e)
{
	// The Closed event is invoked when the
	// popup has been closed and can be used to 
	// destroy the control, perform an action, etc.

	System.Diagnostics.Debug.WriteLine("Closed");
}

private void ultraPopupControlContainer1_Opened(object sender, System.EventArgs e)
{
	// The Opened event is invoked after the popup 
	// has been displayed and can be used to further 
	// initialize the popup

	// For example, you can set focus to the control it displayed
	//
	UltraPopupControlContainer popup = sender as UltraPopupControlContainer;

	// the control that will be displayed can be initialized here
	if (!popup.PopupControl.ContainsFocus)
		popup.PopupControl.Focus();
}

private void ultraPopupControlContainer1_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
	UltraPopupControlContainer popup = sender as UltraPopupControlContainer;

	TreeView tree = this.treeList;

	// the control that will be displayed can be initialized here
	if (popup.PopupControl != tree)
		popup.PopupControl = tree;

	// this Opening event will normally be used to initialize
	// the control that will be dropped down
	this.InitializeDropDownTree(tree);
}

private void InitializeDropDownTree(TreeView tree)
{
	// initialize the tree that we will be dropping down
	// clear any existing nodes
	tree.Nodes.Clear();

	// allow for full row selection
	tree.FullRowSelect = true;
	tree.ShowLines = false;
	tree.ShowRootLines = false;

	// only show a single border
	tree.BorderStyle = BorderStyle.FixedSingle;

	// create the nodes
	tree.Nodes.Add("New");
	tree.Nodes.Add("Open Existing");
	tree.Nodes.Add("Open Recent");

	// select the first node
	tree.SelectedNode = tree.Nodes[0];

	// size the control so it shows all the nodes
	int top = tree.Nodes[0].Bounds.Top;
	int bottom = tree.Nodes[tree.Nodes.Count - 1].Bounds.Bottom;
	tree.ClientSize = new Size(tree.ClientSize.Width, bottom - top);

}

private void treeList_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
	// when the enter key is pressed invoke
	// the tree's Click event
	if (e.KeyCode == Keys.Return)
		this.InvokeOnClick(this.treeList, EventArgs.Empty);
	else if (e.KeyCode == Keys.Escape)
	{
		// then get the popup control container that is
		// displaying the tree and close it
		UltraPopupControlContainer popup = UltraPopupControlContainer.FromControl(sender as Control);

		if (popup != null)
			popup.Close();
	}
}

private void treeList_Click(object sender, System.EventArgs e)
{
	TreeView tree = sender as TreeView;

	// get the selected node and perform some action on it
	TreeNode node = tree.SelectedNode;

	System.Diagnostics.Debug.WriteLine("Node Clicked:" + node.Text);

	// then get the popup control container that is
	// displaying the tree and close it
	UltraPopupControlContainer popup = UltraPopupControlContainer.FromControl(tree);

	if (popup != null)
		popup.Close();
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also