Syncfusion.Shared.Base
Members 


Syncfusion.Windows.Forms Namespace : PopupControlContainer Class

PopupControlContainer Class

A panel-derived class that will let you design custom popups within a form's designer.
Object Model
PopupControlContainer ClassIPopupChild InterfacePopupHost ClassIPopupParent Interface
Syntax
'Declaration
 
<DescriptionAttribute("A panel-derived class that will let you design custom popups within a designer.")>
<DesignerSerializerAttribute(SerializerTypeName="Syncfusion.Windows.Forms.PopupControlContainerSerializer, Syncfusion.Shared.Base, Version=17.1460.0.47, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89", SerializerBaseTypeName="System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>
<ToolboxBitmapAttribute()>
Public Class PopupControlContainer 
   Inherits System.Windows.Forms.Panel
   Implements IKeyboardProcHookClient, IMouseHookHLProcClient, INeedKeyboardMessages, INeedMouseMoveMessages, IPopupChild, IPopupControlContainer, IPopupItem, IPopupParent 
'Usage
 
Dim instance As PopupControlContainer
[Description("A panel-derived class that will let you design custom popups within a designer.")]
[DesignerSerializer(SerializerTypeName="Syncfusion.Windows.Forms.PopupControlContainerSerializer, Syncfusion.Shared.Base, Version=17.1460.0.47, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89", SerializerBaseTypeName="System.ComponentModel.Design.Serialization.CodeDomSerializer, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[ToolboxBitmap()]
public class PopupControlContainer : System.Windows.Forms.Panel, IKeyboardProcHookClient, IMouseHookHLProcClient, INeedKeyboardMessages, INeedMouseMoveMessages, IPopupChild, IPopupControlContainer, IPopupItem, IPopupParent  
Remarks

To design a custom popup, drag-and-drop it off the toolbox into a form during design-time. Then populate it with appropriate controls just like you would any other panel. You can mark it as invisible (Visible = false) so that it will not interfere with the form's layout mechanism. It's also recommended that you unparent it from the design-time parent in your form constructor code, as shown in the sample code below.

When you are ready to popup, call this class's ShowPopup method. This will show the popup at the specified location.

There are different configurations in which you can use this PopupControlContainer.

  • When you specify a Parent Control using ParentControl and pass a Point.Empty location to ShowPopup, the popup location will be dynamically determined based on the ParentControl's bounds and the screen area.
  • For even more control over the alignment and positioning of the popup, you should implement an IPopupParent interface and assign that to the PopupParent property (this you would do instead of the above PopupControl-based alignment.).

When the popup is showing, the PopupControlContainer, in the ProcessDialogKey override will look for Alt, Enter, Tab, Esc, F4, and F2 keys and either cancel or close the popup. If you want to prevent this, then set IgnoreDialogKey to False. You should then make sure to close the popup manually whenever appropriate using HidePopup(PopupCloseType).

The PopupControlContainer also fires the BeforePopup, Popup(after popup) and CloseUp events that you can handle. You could for example set the focus on a control within the PopupControlContainer in the popup event handler.

Example
The following example has a PopupControlContainer that gets shown when the user does an Alt+DownArrow on a text box. public Form1() { InitializeComponent(); // It's recommended that you keep the PopupControlContainer unparented by // any control on the form (which will be the default case as set up during design-time). // Otherwise, the Form won't close sometimes after dropping down this popup! this.popupControlContainer1.Parent.Controls.Remove(this.popupControlContainer1); } #region Windows Form Designer generated code private void InitializeComponent() { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.popupControlContainer1 = new Syncfusion.Windows.Forms.PopupControlContainer(); this.cancel = new System.Windows.Forms.Button(); this.OK = new System.Windows.Forms.Button(); this.popupTextBox = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.sourceTextBox = new System.Windows.Forms.TextBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.dropDownBtn = new System.Windows.Forms.Button(); this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.popupControlContainer1.SuspendLayout(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // // popupControlContainer1 // this.popupControlContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.popupControlContainer1.Controls.AddRange(new System.Windows.Forms.Control[] { this.cancel, this.OK, this.popupTextBox}); this.popupControlContainer1.Location = new System.Drawing.Point(80, 128); this.popupControlContainer1.Name = "popupControlContainer1"; this.popupControlContainer1.Size = new System.Drawing.Size(120, 128); this.popupControlContainer1.TabIndex = 0; this.popupControlContainer1.Visible = false; this.popupControlContainer1.Popup += new System.EventHandler(this.popupControlContainer1_Popup); this.popupControlContainer1.CloseUp += new Syncfusion.Windows.Forms.PopupClosedEventHandler(this.popupControlContainer1_CloseUp); this.popupControlContainer1.BeforePopup += new System.ComponentModel.CancelEventHandler(this.popupControlContainer1_BeforePopup); // // cancel // this.cancel.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); this.cancel.Location = new System.Drawing.Point(64, 96); this.cancel.Name = "cancel"; this.cancel.Size = new System.Drawing.Size(48, 24); this.cancel.TabIndex = 2; this.cancel.Text = "Cancel"; this.cancel.Click += new System.EventHandler(this.cancelButton_Click); // // OK // this.OK.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right); this.OK.Location = new System.Drawing.Point(8, 96); this.OK.Name = "OK"; this.OK.Size = new System.Drawing.Size(48, 24); this.OK.TabIndex = 1; this.OK.Text = "OK"; this.OK.Click += new System.EventHandler(this.OK_Click); // // popupTextBox // this.popupTextBox.Multiline = true; this.popupTextBox.Name = "popupTextBox"; this.popupTextBox.Size = new System.Drawing.Size(118, 90); this.popupTextBox.TabIndex = 0; this.popupTextBox.Text = ""; // // label1 // this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.label1.Location = new System.Drawing.Point(16, 56); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(256, 64); this.label1.TabIndex = 1; this.label1.Text = "Associate a PopupControlContainer with this TextBox. And also transfer data back " + "and forth between the popup and the TextBox."; // // sourceTextBox // this.sourceTextBox.Location = new System.Drawing.Point(40, 128); this.sourceTextBox.Name = "sourceTextBox"; this.sourceTextBox.Size = new System.Drawing.Size(200, 20); this.sourceTextBox.TabIndex = 2; this.sourceTextBox.Text = "Alt+DownArrow for popup"; this.sourceTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBoxPopupParent_KeyDown); // // groupBox1 // this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] { this.dropDownBtn}); this.groupBox1.Location = new System.Drawing.Point(8, 32); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(280, 128); this.groupBox1.TabIndex = 3; this.groupBox1.TabStop = false; this.groupBox1.Text = "PopupControlContainer demo"; // // dropDownBtn // this.dropDownBtn.Image = ((System.Drawing.Bitmap)(resources.GetObject("dropDownBtn.Image"))); this.dropDownBtn.Location = new System.Drawing.Point(240, 96); this.dropDownBtn.Name = "dropDownBtn"; this.dropDownBtn.Size = new System.Drawing.Size(26, 20); this.dropDownBtn.TabIndex = 0; this.dropDownBtn.Click += new System.EventHandler(this.dropDownBtn_Click); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2}); this.menuItem1.Text = "Help"; // // menuItem2 // this.menuItem2.Index = 0; this.menuItem2.Text = "About Syncfusion"; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.sourceTextBox, this.label1, this.popupControlContainer1, this.groupBox1}); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Menu = this.mainMenu1; this.Name = "Form1"; this.Text = "Custom Popups Dialog"; this.popupControlContainer1.ResumeLayout(false); this.groupBox1.ResumeLayout(false); this.ResumeLayout(false); } #endregion [STAThread] public static void Main() { Application.Run(new Form1()); } #region OpenClosePopup private void textBoxPopupParent_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { // Using this unconventional if statement syntax to avoid "and" symbol (documentation restriction, please ignore). // If user pressed key down, then show the popup. if(e.Alt) if(e.KeyCode == Keys.Down) if(!this.popupControlContainer1.IsShowing()) { // Let the popup align around the source textBox. this.popupControlContainer1.ParentControl = this.sourceTextBox; // Passing Point.Empty will align it automatically around the above ParentControl. this.popupControlContainer1.ShowPopup(Point.Empty); e.Handled = true; } // Escape should close the popup. if(e.KeyCode == Keys.Escape) if(this.popupControlContainer1.IsShowing()) this.popupControlContainer1.HidePopup(PopupCloseType.Canceled); } private void OK_Click(object sender, System.EventArgs e) { this.popupControlContainer1.HidePopup(PopupCloseType.Done); } private void cancelButton_Click(object sender, System.EventArgs e) { this.popupControlContainer1.HidePopup(PopupCloseType.Canceled); } #endregion OpenClosePopup #region PopupEvents private void popupControlContainer1_BeforePopup(object sender, System.ComponentModel.CancelEventArgs e) { // Set the text to be edited with the text in the form text box. this.popupTextBox.Text = this.sourceTextBox.Text; } private void popupControlContainer1_Popup(object sender, System.EventArgs e) { // Set the focus on the text box inside the popup after it is open. this.popupTextBox.Focus(); this.popupTextBox.SelectionStart = 0; this.popupTextBox.SelectionLength = 0; } private void popupControlContainer1_CloseUp(object sender, Syncfusion.Windows.Forms.PopupClosedEventArgs args) { // Transfer data from the popup. if(args.PopupCloseType == PopupCloseType.Done) { this.sourceTextBox.Text = this.popupTextBox.Text; } // Set focus back to textbox. if(args.PopupCloseType == PopupCloseType.Done || args.PopupCloseType == PopupCloseType.Canceled) this.sourceTextBox.Focus(); } #endregion PopupEvents Public Sub New() MyBase.New() InitializeComponent() ' It's recommended that you keep the PopupControlContainer unparented by ' any Control on the Form (which will be the default case as set up during design-time). ' Otherwise, the Form wouldn't close sometimes, after dropping down this popup! Me.popupControlContainer1.Parent.Controls.Remove(Me.popupControlContainer1) End Sub Private Sub InitializeComponent() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.popupControlContainer1 = New Syncfusion.Windows.Forms.PopupControlContainer() Me.cancel = New System.Windows.Forms.Button() Me.OK = New System.Windows.Forms.Button() Me.popupTextBox = New System.Windows.Forms.TextBox() Me.label1 = New System.Windows.Forms.Label() Me.sourceTextBox = New System.Windows.Forms.TextBox() Me.groupBox1 = New System.Windows.Forms.GroupBox() Me.dropDownBtn = New System.Windows.Forms.Button() Me.mainMenu1 = New System.Windows.Forms.MainMenu() Me.menuItem1 = New System.Windows.Forms.MenuItem() Me.menuItem2 = New System.Windows.Forms.MenuItem() Me.popupControlContainer1.SuspendLayout() Me.groupBox1.SuspendLayout() Me.SuspendLayout() ' ' popupControlContainer1 ' Me.popupControlContainer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.popupControlContainer1.Controls.AddRange(New System.Windows.Forms.Control() {Me.cancel, Me.OK, Me.popupTextBox}) Me.popupControlContainer1.Location = New System.Drawing.Point(80, 128) Me.popupControlContainer1.Name = "popupControlContainer1" Me.popupControlContainer1.Size = New System.Drawing.Size(120, 128) Me.popupControlContainer1.TabIndex = 0 Me.popupControlContainer1.Visible = False AddHandler Me.popupControlContainer1.Popup, New System.EventHandler(AddressOf popupControlContainer1_Popup) AddHandler Me.popupControlContainer1.CloseUp, New Syncfusion.Windows.Forms.PopupClosedEventHandler(AddressOf popupControlContainer1_CloseUp) AddHandler Me.popupControlContainer1.BeforePopup, New System.ComponentModel.CancelEventHandler(AddressOf popupControlContainer1_BeforePopup) ' ' cancel ' Me.cancel.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.cancel.Location = New System.Drawing.Point(64, 96) Me.cancel.Name = "cancel" Me.cancel.Size = New System.Drawing.Size(48, 24) Me.cancel.TabIndex = 2 Me.cancel.Text = "Cancel" AddHandler Me.cancel.Click, New System.EventHandler(AddressOf cancelButton_Click) ' ' OK ' Me.OK.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.OK.Location = New System.Drawing.Point(8, 96) Me.OK.Name = "OK" Me.OK.Size = New System.Drawing.Size(48, 24) Me.OK.TabIndex = 1 Me.OK.Text = "OK" AddHandler Me.OK.Click, New System.EventHandler(AddressOf OK_Click) ' ' popupTextBox ' Me.popupTextBox.Multiline = True Me.popupTextBox.Name = "popupTextBox" Me.popupTextBox.Size = New System.Drawing.Size(118, 90) Me.popupTextBox.TabIndex = 0 Me.popupTextBox.Text = "" ' ' label1 ' Me.label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.label1.Location = New System.Drawing.Point(16, 56) Me.label1.Name = "label1" Me.label1.Size = New System.Drawing.Size(256, 64) Me.label1.TabIndex = 1 Me.label1.Text = ("Associate a PopupControlContainer with this TextBox. And also transfer data back " + "and forth between the popup and the TextBox.") ' ' sourceTextBox ' Me.sourceTextBox.Location = New System.Drawing.Point(40, 128) Me.sourceTextBox.Name = "sourceTextBox" Me.sourceTextBox.Size = New System.Drawing.Size(200, 20) Me.sourceTextBox.TabIndex = 2 Me.sourceTextBox.Text = "Alt+DownArrow for popup" AddHandler Me.sourceTextBox.KeyDown, New System.Windows.Forms.KeyEventHandler(AddressOf textBoxPopupParent_KeyDown) ' ' groupBox1 ' Me.groupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.dropDownBtn}) Me.groupBox1.Location = New System.Drawing.Point(8, 32) Me.groupBox1.Name = "groupBox1" Me.groupBox1.Size = New System.Drawing.Size(280, 128) Me.groupBox1.TabIndex = 3 Me.groupBox1.TabStop = False Me.groupBox1.Text = "PopupControlContainer demo" ' ' dropDownBtn ' Me.dropDownBtn.Image = CType(resources.GetObject("dropDownBtn.Image"), System.Drawing.Bitmap) Me.dropDownBtn.Location = New System.Drawing.Point(240, 96) Me.dropDownBtn.Name = "dropDownBtn" Me.dropDownBtn.Size = New System.Drawing.Size(26, 20) Me.dropDownBtn.TabIndex = 0 AddHandler Me.dropDownBtn.Click, New System.EventHandler(AddressOf dropDownBtn_Click) ' ' mainMenu1 ' Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem1}) ' ' menuItem1 ' Me.menuItem1.Index = 0 Me.menuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem2}) Me.menuItem1.Text = "Help" ' ' menuItem2 ' Me.menuItem2.Index = 0 Me.menuItem2.Text = "About Syncfusion" AddHandler Me.menuItem2.Click, New System.EventHandler(AddressOf menuItem2_Click) ' ' Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 273) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.sourceTextBox, Me.label1, Me.popupControlContainer1, Me.groupBox1}) Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) Me.Menu = Me.mainMenu1 Me.Name = "Form1" Me.Text = "Custom Popups Dialog" Me.popupControlContainer1.ResumeLayout(False) Me.groupBox1.ResumeLayout(False) Me.ResumeLayout(False) End Sub Private Sub textBoxPopupParent_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) ' Using this unconventional if statement syntax to avoid "and" symbol (documentation restriction, please ignore). ' If user pressed key down, then show the popup. ' Escape should close the popup. If e.Alt Then If (e.KeyCode = Keys.Down) Then If Not (Me.popupControlContainer1.IsShowing) Then ' Let the popup align around the source textBox. Me.popupControlContainer1.ParentControl = Me.sourceTextBox ' Passing Point.Empty will align it automatically around the above ParentControl. Me.popupControlContainer1.ShowPopup(Point.Empty) e.Handled = True End If End If End If If (e.KeyCode = Keys.Escape) Then If Me.popupControlContainer1.IsShowing Then Me.popupControlContainer1.HidePopup(PopupCloseType.Canceled) End If End If End Sub Private Sub OK_Click(ByVal sender As Object, ByVal e As EventArgs) Me.popupControlContainer1.HidePopup(PopupCloseType.Done) End Sub Private Sub cancelButton_Click(ByVal sender As Object, ByVal e As EventArgs) Me.popupControlContainer1.HidePopup(PopupCloseType.Canceled) End Sub Private Sub popupControlContainer1_BeforePopup(ByVal sender As Object, ByVal e As CancelEventArgs) ' Set the text to be edited with the text in the form text box. Me.popupTextBox.Text = Me.sourceTextBox.Text End Sub Private Sub popupControlContainer1_Popup(ByVal sender As Object, ByVal e As EventArgs) ' Set the focus on the text box inside the popup after its open. Me.popupTextBox.Focus() Me.popupTextBox.SelectionStart = 0 Me.popupTextBox.SelectionLength = 0 End Sub Private Sub popupControlContainer1_CloseUp(ByVal sender As Object, ByVal args As PopupClosedEventArgs) ' Transfer data from the popup. ' Set focus back to textbox. If (args.PopupCloseType = PopupCloseType.Done) Then Me.sourceTextBox.Text = Me.popupTextBox.Text End If If ((args.PopupCloseType = PopupCloseType.Done) _ OrElse (args.PopupCloseType = PopupCloseType.Canceled)) Then Me.sourceTextBox.Focus() End If End Sub
Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            System.Windows.Forms.ScrollableControl
               System.Windows.Forms.Panel
                  Syncfusion.Windows.Forms.PopupControlContainer
                     Syncfusion.Windows.Forms.Grid.GridDropDownContainer
                     Syncfusion.Windows.Forms.Tools.CalendarPopup
                     Syncfusion.Windows.Forms.Tools.ComboBoxPopupControl
                     Syncfusion.Windows.Forms.Tools.RadialMenu
                     Syncfusion.Windows.Forms.Tools.RibbonMinimizePopUp
                     Syncfusion.Windows.Forms.Tools.SizablePopupControlContainer
                     Syncfusion.Windows.Forms.Tools.XPMenus.ListBoxContainer
                     Syncfusion.Windows.Forms.ToolTipAdv

AssemblyVersion

Syncfusion.Shared.Base: 17.1460.0.47

See Also