Click here to Skip to main content
13,350,289 members (47,163 online)
Click here to Skip to main content
Add your own
alternative version


512 bookmarked
Posted 3 Feb 2007

Simple Popup Control

, 26 Mar 2013
Rate this:
Please Sign up or sign in to vote.
How to create a custom pop-up control in C#.
Sample application using a custom popup control:

Custom popup control

Another application using a custom tooltip...

Custom tooltip

... and a more complex popup that can be resized:

Resizable popup

Tracking popup opening below the specified part of a control:

Tracking popup

Cascade of popup controls:

Cascade of popup controls


Popup windows are everywhere. Each tooltip is a popup window; each combobox has its popup list; many advertisements are also shown in popup windows.

How to Create a Popup Control in .NET?

At first, we might choose the Form class as a base class for our popup control. Unfortunately, it is a bad choice because when we show our popup form, the parent form loses its focus. A popup window should not cause that. Luckily, there is a class that does not cause loss of focus. We can use it as a base class for our popup control. It is the ToolStripDropDown class.

How to Use the ToolStripDropDown Class?

This would be the simplest way, without deriving from that class:

ToolStripDropDown popup = new ToolStripDropDown();
popup.Margin = Padding.Empty;
popup.Padding = Padding.Empty;
ToolStripControlHost host = new ToolStripControlHost(content);
host.Margin = Padding.Empty;
host.Padding = Padding.Empty;
popup.Show(parentForm, location);

In this case, content is a control we want to show in a popup window. Of course, we have to remember to later dispose the popup window and its contents.

Popup Class

I wrote a Popup class that derives from ToolStripDropDown and simplifies the creating and managing of popup windows. The class calculates by itself where it should "pop" on the screen. It also disposes itself immediately after disposing the content control. To show a popup with a button, for example, we could write:

new Popup(new Button()).Show(someControl);

Here, someControl would be a control below which we want to show our popup.

Popup Resizing

To enable resizing for your popup, you must set the Resizable property to true and add the following code into your content control class:

protected override void WndProc(ref Message m)
    if ((Parent as Popup).ProcessResizing(ref m)) return;
    base.WndProc(ref m);

You also have to set the ResizeRedraw property of the content control to true.


To specify the minimum and maximum size of the content control, please use the following properties:

  • content.MinimumSize and content.MaximumSize only inside the constructor of the content control
  • popup.MinimumSize and popup.MaximumSize elsewhere

ComboBox Class

The System.Windows.Forms.ComboBox class behaves in a strange way when it is on a popup control. It closes the popup control when the user clicks on a part of the combobox's dropdown that sticks out of a popup. So, I have created a PopupControl.ComboBox class that behaves properly.

PopupComboBox Class

This is a base class for comboboxes that can have a custom dropdown attached.

Animation Support

Animation is enabled by default. To change it, set the AnimationDuration, HidingAnimation, and ShowingAnimation properties.

Popup Members


  • AcceptAlt — Gets or sets a value indicating whether pressing the Alt key should close the popup.
  • AnimationDuration — Determines the duration of the animation.
  • Content — Gets the content of the popup.
  • FocusOnOpen — Gets or sets a value indicating whether the content should receive the focus after the popup has been opened.
  • HidingAnimation — Determines which animation to use while hiding the popup window.
  • MaximumSize — Gets or sets a maximum size of the popup.
  • MinimumSize — Gets or sets a minimum size of the popup.
  • NonInteractive — Gets or sets a value indicating whether the popup acts like a transparent windows; e.g., it cannot be clicked (note — it does not affect child controls).
  • Resizable — Gets or sets a value indicating whether the popup is resizable.
  • ShowingAnimation — Determines which animation to use while showing the popup window.


  • Popup(Control content) — Initializes a new instance of the Popup class.


  • void PaintSizeGrip(PaintEventArgs e) — Paints the sizing grip.
  • bool ProcessResizing(ref Message m) — Processes the resizing messages.
  • void Show(Control control) — Shows the popup window below the specified control.
  • void Show(Control control, Rectangle area) — Shows the popup window below the specified area of the specified control.


  • Base class for custom tooltips.
  • Office 2007-like tooltip class.


  • 1.5 (20.10.2010) — Important! This is the last “standalone” version of the control. The next version is included in a new project hosted at CodePlex.
    • Added the NonInteractive property to the Popup class.
    • Fixed resizing on DualView/multi monitor systems.
    • Popup is now always shown on top of other windows (previously the popup could be shown below its parent during the animation process).
    • PopupComboBox didn’t properly set focus to its dropdown on Windows 7.
    • Improved compatibility with Mono.
    • Uses C# 3.0 syntax (auto-properties, lambdas).
    • Signed binaries for both .NET 2.0 and .NET 4.0 are available.
    • Solution upgraded to the Visual C# 2010 format.
    • License changed to LGPL 3.0.
  • 1.4 (16.01.2009)
    • Added the DroppedDown property, and the DropDown, DropDownClosed events to the PopupComboBox class.
    • Fixed resizing of a popup when the MaximumSize property of the content control is not set.
  • 1.3.1 (20.09.2008)
    • Tab-key properly transfers the focus between controls contained in a popup window.
    • Minor bugs fixed.
  • 1.3 (04.05.2008)
    • Added the AnimationDuration, HidingAnimation, and ShowingAnimation properties.
    • Removed the UseFadeEffect property.
    • Popup control can animate now even when the FocusOnOpen property is set to false.
  • 1.2.5 (24.01.2008)
    • Fixed “Alt+F4” bug.
    • Fixed drawing the sizing grip.
    • Minor bugs fixed.
  • 1.2 (24.07.2007)
    • Added animation support.
    • Added AcceptAlt property.
    • Clicking on the non-client area bug fixed.
    • Minor bugs fixed.
  • 1.1 (05.07.2007)
    • Added XML documentation.
    • "Fixed" the ComboBox class, so it can be used inside a popup.
    • Added base class for a combobox that can have a custom dropdown, PopupComboBox.
    • The sizing grip is automatically drawn if a popup is resizable.
    • Added support for a minimum and maximum size of a resizable popup.
    • Minor bugs fixed.
  • 1.0
    • 08.06.2007 – Added resizing support and capability for using cascading pop-ups.
    • 06.02.2007 – Added keyboard and custom region support, and the ShowForControl method name changed to Show.
    • 03.02.2007 – First version.


This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


About the Author

Lukasz Swiatkowski
Software Developer
Poland Poland
I am a graduate of Wroclaw University of Technology, Poland.

My interests: reading, programming, drawing, Japan, yoga, tai-chi.

My websites:,

You may also be interested in...


Comments and Discussions

QuestionBon travail Pin
AMINE ARAFY17-Jan-12 2:39
memberAMINE ARAFY17-Jan-12 2:39 
GeneralMy vote of 5 Pin
Muhammad Dehghan8-Jan-12 22:11
memberMuhammad Dehghan8-Jan-12 22:11 
GeneralRe: My vote of 5 Pin
Lukasz Swiatkowski16-Sep-12 23:54
memberLukasz Swiatkowski16-Sep-12 23:54 
QuestionTwo ToolStripDropDown at the same time Pin
Ivan Chepiga2-Nov-11 23:19
memberIvan Chepiga2-Nov-11 23:19 
QuestionShow(ToolStripItem) overload Pin
Member 38586382-Nov-11 7:11
memberMember 38586382-Nov-11 7:11 
QuestionCheckboxComboBox should allow text search like ComboBoxStyle = DropDown which is not happening :( Pin
Member 827966029-Sep-11 19:18
memberMember 827966029-Sep-11 19:18 
QuestionPopping up MonthCalendar Control Pin
Member 226177512-Aug-11 6:52
memberMember 226177512-Aug-11 6:52 
QuestionThe thing with the dropdown Arrow Pin
pamkkkkk23-Jun-11 23:41
memberpamkkkkk23-Jun-11 23:41 
Some Times there is only a small difference, between to make things work and make it work correctly ! Wink | ;)

You are using for the drop down Arrow, the Font Marlett and the Char 'u' to display it (if I see it correctly).
But whats shows up, if the User did not have installed the Font!? (Chinise People, or Kyrylic ...)

So using Font is not the solution!

Next idea can be, to use a Bitmap to show the Arrow.
Yes! That is working!
But what if the user changes his VisualStyles onto Windows ?
It Looks ugly !?

But Microsoft has a better solution for us (wich is harder to code)
Look into the sourcecode of this Project into the overridden Paint event Handler:

In case, the User hase switched on the VisualStyles, the ComboBoxRenderer.DrawDropDownButton will be used to display every Button state correctly (ComboBoxState.Pressed or ComboBoxState.Hot ...)

If the User doesnot switched on the VisualStyles, you have to draw the Arrow with graphics.DrawPolygon by your self and the background of the Button stays Clean!

Just my 50 cent..... Rose | [Rose]
AnswerRe: The thing with the dropdown Arrow Pin
Lukasz Swiatkowski24-Jun-11 3:07
memberLukasz Swiatkowski24-Jun-11 3:07 
GeneralRe: The thing with the dropdown Arrow Pin
pamkkkkk24-Jun-11 3:40
memberpamkkkkk24-Jun-11 3:40 
GeneralMy vote of 5 Pin
pamkkkkk23-Jun-11 22:36
memberpamkkkkk23-Jun-11 22:36 
GeneralRe: My vote of 5 Pin
Lukasz Swiatkowski24-Jun-11 3:02
memberLukasz Swiatkowski24-Jun-11 3:02 
GeneralThank you! Pin
Ravi Bhavnani23-Apr-11 17:12
memberRavi Bhavnani23-Apr-11 17:12 
GeneralRe: Thank you! Pin
Lukasz Swiatkowski24-Jun-11 3:01
memberLukasz Swiatkowski24-Jun-11 3:01 
QuestionDo you have old version for .net 2.0 framework ? Pin
Berni124-Feb-11 12:13
memberBerni124-Feb-11 12:13 
AnswerRe: Do you have old version for .net 2.0 framework ? Pin
Lukasz Swiatkowski24-Feb-11 21:23
memberLukasz Swiatkowski24-Feb-11 21:23 
GeneralMy vote of 5 Pin
Member 25952581-Jan-11 8:53
memberMember 25952581-Jan-11 8:53 
GeneralRe: My vote of 5 Pin
Lukasz Swiatkowski24-Jan-11 19:45
memberLukasz Swiatkowski24-Jan-11 19:45 
GeneralGreat Control, but how to manage textbox focus..! [modified] Pin
nnihadnoordeenn12-Nov-10 3:16
membernnihadnoordeenn12-Nov-10 3:16 
GeneralRe: Great Control, but how to manage textbox focus..! Pin
Lukasz Swiatkowski24-Jan-11 19:44
memberLukasz Swiatkowski24-Jan-11 19:44 
QuestionRe: Great Control, but how to manage textbox focus..! [modified] Pin
Member 354174623-Apr-12 21:33
memberMember 354174623-Apr-12 21:33 
GeneralGreat Stuff Pin
Jonathan C Dickinson22-Oct-10 0:03
memberJonathan C Dickinson22-Oct-10 0:03 
GeneralRe: Great Stuff Pin
Lukasz Swiatkowski22-Oct-10 1:16
memberLukasz Swiatkowski22-Oct-10 1:16 
GeneralPopup Resize sometimes doesn't work on a multi monitor system Pin
deep4219-Oct-10 1:39
memberdeep4219-Oct-10 1:39 
GeneralRe: Popup Resize sometimes doesn't work on a multi monitor system Pin
Lukasz Swiatkowski20-Oct-10 10:16
memberLukasz Swiatkowski20-Oct-10 10:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 27 Mar 2013
Article Copyright 2007 by Lukasz Swiatkowski
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid