Skip to main content
Email Password   helpLost your password?

Sample application using a custom popup control:

Custom pop-up control

Another application using a custom tooltip...

Custom tooltip

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

Resizable pop-up

Tracking popup opening below the specified part of a control:

simplepopup.gif

Cascade of popup controls:

Cascade of pop-up controls

Introduction

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.Items.Add(host);
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.

Important!

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

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 AnimationDuration, HidingAnimation and ShowingAnimation properties.

Popup Members

Properties

Constructor

Methods

TODO

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionMono compatibility, again Pin
Gerhard Olsson
14:49 19 Jul '09  
AnswerRe: Mono compatibility, again Pin
Lukasz Swiatkowski
17:49 19 Jul '09  
AnswerQuick fix Pin
Lukasz Swiatkowski
20:33 19 Jul '09  
GeneralRe: Quick fix Pin
Gerhard Olsson
9:40 20 Jul '09  
GeneralRe: Quick fix Pin
Lukasz Swiatkowski
1:26 22 Jul '09  
GeneralGreat !!! Pin
iccb1013
17:02 15 Jul '09  
GeneralRe: Great !!! Pin
Lukasz Swiatkowski
10:20 17 Jul '09  
GeneralToolStripDropDown Not Showing Pin
winheart
22:47 28 Jun '09  
GeneralRe: ToolStripDropDown Not Showing Pin
Lukasz Swiatkowski
8:24 29 Jun '09  
GeneralRe: ToolStripDropDown Not Showing Pin
winheart
2:38 26 Oct '09  
GeneralUse as a ToolTip Pin
Bob Carboni
8:16 18 Jun '09  
GeneralRe: Use as a ToolTip Pin
Lukasz Swiatkowski
10:50 24 Jun '09  
GeneralRe: Use as a ToolTip Pin
Bob Carboni
14:47 24 Jun '09  
GeneralRe: Use as a ToolTip Pin
Lukasz Swiatkowski
8:07 29 Jun '09  
GeneralMatters about using with MonthCalendar Pin
zmfeng(China)
22:10 8 Jun '09  
Generalcommercial distribution question Pin
Silent Winter
4:15 5 May '09  
GeneralRe: commercial distribution question Pin
Lukasz Swiatkowski
8:29 5 May '09  
GeneralRe: commercial distribution question Pin
Silent Winter
11:12 5 May '09  
GeneralRe: commercial distribution question Pin
Lukasz Swiatkowski
11:49 5 May '09  
GeneralMono compatibility Pin
KaSA1
6:55 31 Mar '09  
GeneralRe: Mono compatibility Pin
Lukasz Swiatkowski
7:06 31 Mar '09  
GeneralSwietna robota Lukasz :) Pin
PL01
1:01 12 Mar '09  
GeneralRe: Swietna robota Lukasz :) Pin
Lukasz Swiatkowski
7:00 31 Mar '09  
GeneralNice article, though I disagree.... Pin
Galatei
14:23 13 Jan '09  
GeneralRe: Nice article, though I disagree.... Pin
demogodyou
23:00 14 Jan '09  


Last Updated 16 Jan 2009 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009