Click here to Skip to main content
11,797,355 members (70,625 online)
Click here to Skip to main content

Display any usercontrol as a popup menu

, 1 May 2005 181.7K 4K 125
Rate this:
Please Sign up or sign in to vote.
This article introduces a little class which lets you show any usercontrol in XP style popup menu.


I found it frustrating that the .NET framework does not provide custom menus. I realized that you can owner-draw menus, but sometimes you just want to do more. I started with this little class which at the beginning was used for displaying a usercontrol in a floating window. Now, I have added several improvements to it.

  1. I wanted my popup to appear at the top of a button (like the Start menu in Windows). But only if there is enough place.
  2. The menu shows shadows (see the picture).
  3. The menu appears with a quick and graphically pleasing animation.

On the contrary of what I could find on the internet, this class lets you show any type of control. There is no need to derive from any special class. Also the popup will appear where you want it, on the screen. I used a button but you can use an image or anything that you like.

Using the code

To try the class, just run the Test project provided. I have tried to keep this class simple to use. To use it in your own project, you just need two lines of code. First add the popup.vb file to your project.

If you want to display usercontrol1 when button1 is clicked, you just need these two lines of code:

Private Sub Button1_Click(ByVal sender As System.Object, 
   ByVal e As System.EventArgs) 
      _ Handles Button1.Click
 popup = New Popup(New UserControl1, Button1)
End Sub

By default, the popup will appear animated with a shadow and a dark grey border.

You can change these settings if you want to. Note that the shadow part of this code was derived from a C# article called Add a drop shadow to a form by David M. Kean. This feature (and this feature only) will work only on Windows XP.

The popup will disappear automatically when its window is deactivated. The window is deactivated as soon as you click outside the popup. The component also offers two events DropDown and DropDownClosed. You can use this class to initialize or save your usercontrol values.

Private Sub PopupDown(ByVal Sender As Object, ByVal e As EventArgs) _
          Handles popup.DropDown
 Me.Text = "Popup is open"
 End Sub

 Private Sub PopupClosed(ByVal Sender As Object, ByVal e As EventArgs) _
          Handles popup.DropDownClosed
 Me.Text = "Popup is closed"
 End Sub

Points of interest

No rocket science, just a lightweight small class.

The positioning of the popup is more complicated than I expected, so you don't have to think about it.


  • 6 Feb. 2005 - First version released.
    • The Resizable option does not resize very smoothly. The rest seems to work well.
  • 12 Feb. 2005
    • The popup does not appear in the task bar anymore (thank you steve).
    • The usercontrol can now prevent the popup from closing if it wants.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Pascal Ganaye
Software Developer (Senior)
United Kingdom United Kingdom
I am a French programmer.
These days I spend most of my time with the .NET framework, JavaScript and html.

You may also be interested in...

Comments and Discussions

QuestionPopup Position Pin
msov28-Mar-12 5:18
membermsov28-Mar-12 5:18 
GeneralMy vote of 5 Pin
Asif Imam13-Feb-12 22:10
memberAsif Imam13-Feb-12 22:10 
GeneralOnDeactivate kills the events in UserControl Pin
Matt-HH3-Nov-10 13:14
memberMatt-HH3-Nov-10 13:14 
GeneralRe: OnDeactivate kills the events in UserControl Pin
Matt-HH4-Nov-10 6:36
memberMatt-HH4-Nov-10 6:36 
GeneralDateTimePicker selection bug Pin
Jiong Mai21-Jan-09 7:01
memberJiong Mai21-Jan-09 7:01 
GeneralThank you, Pascal! Pin
Big Dog23-Apr-08 13:30
memberBig Dog23-Apr-08 13:30 
QuestionModal Dialog Pin
E! Ray K13-Mar-08 5:30
memberE! Ray K13-Mar-08 5:30 
QuestionShow from UserControl??? Pin
Lelo LXXIV15-Nov-07 22:08
memberLelo LXXIV15-Nov-07 22:08 
QuestionC # version of this control Pin
Rei Masi13-Nov-07 10:09
memberRei Masi13-Nov-07 10:09 
AnswerRe: C # version of this control Pin
Big Dog23-Apr-08 13:33
memberBig Dog23-Apr-08 13:33 
GeneralA little Problem Pin
kapil bhavsar4-Apr-07 3:06
memberkapil bhavsar4-Apr-07 3:06 
GeneralRe: A little Problem Pin
nzin12-Aug-07 20:29
membernzin12-Aug-07 20:29 
NewsLicensing Pin
Pascal Ganaye5-Mar-07 2:30
memberPascal Ganaye5-Mar-07 2:30 
GeneralRe: Licensing Pin
blumenhause25-May-07 18:54
memberblumenhause25-May-07 18:54 
GeneralTextbox search popup Pin
E! Ray K23-Jan-07 10:03
memberE! Ray K23-Jan-07 10:03 
GeneralRe: Textbox search popup Pin
Pascal Ganaye5-Mar-07 2:25
memberPascal Ganaye5-Mar-07 2:25 
GeneralRe: Textbox search popup Pin
connectpalm3-Apr-07 1:50
memberconnectpalm3-Apr-07 1:50 
GeneralReally great, but... :) Pin
KStankov14-Dec-06 18:49
memberKStankov14-Dec-06 18:49 
GeneralGreat control! Pin
blumenhause28-Oct-06 7:12
memberblumenhause28-Oct-06 7:12 
GeneralUsing Your Source Pin
Bernard C20-Sep-06 0:15
memberBernard C20-Sep-06 0:15 
GeneralBlack Flickering Pin
codedieb23-May-06 11:25
membercodedieb23-May-06 11:25 
GeneralRe: Black Flickering Pin
Pascal Ganaye5-Jun-06 7:16
memberPascal Ganaye5-Jun-06 7:16 
GeneralVery nice control Pin
jasonpb31-Jan-06 14:56
memberjasonpb31-Jan-06 14:56 
GeneralClose on UserControl Button Click Pin
MartAlex20-May-05 9:26
memberMartAlex20-May-05 9:26 
GeneralRe: Close on UserControl Button Click [modified] Pin
codedieb23-May-06 4:12
membercodedieb23-May-06 4:12 
GeneralAbout the Interface IPopupUserControl Pin
dyh222218-May-05 3:22
memberdyh222218-May-05 3:22 
GeneralDrawGrip Pin
Laurent Muller10-May-05 20:05
memberLaurent Muller10-May-05 20:05 
GeneralRe: DrawGrip Pin
pascal ganaye24-May-05 10:35
memberpascal ganaye24-May-05 10:35 
GeneralParent form looses focus Pin
2scoops.net4-May-05 5:35
member2scoops.net4-May-05 5:35 
GeneralRe: Parent form looses focus Pin
pascal ganaye4-May-05 9:21
memberpascal ganaye4-May-05 9:21 
GeneralRe: Parent form looses focus Pin
axelriet26-Jun-05 1:33
memberaxelriet26-Jun-05 1:33 
GeneralRe: Parent form looses focus Pin
dbassett7420-Feb-09 5:41
memberdbassett7420-Feb-09 5:41 
GeneralClosing on click is a problem. Pin
Rüdiger Klaehn2-May-05 0:34
memberRüdiger Klaehn2-May-05 0:34 
GeneralRe: Closing on click is a problem. Pin
Thomas Freudenberg2-May-05 1:30
memberThomas Freudenberg2-May-05 1:30 
GeneralRe: Closing on click is a problem. Pin
Dean_DOT2-May-05 6:44
memberDean_DOT2-May-05 6:44 
GeneralRe: Closing on click is a problem. Pin
pascal ganaye2-May-05 9:16
memberpascal ganaye2-May-05 9:16 
GeneralRe: Closing on click is a problem. Pin
Rogier13-May-05 1:38
memberRogier13-May-05 1:38 
GeneralRe: Closing on click is a problem. Pin
pascal ganaye13-May-05 7:44
memberpascal ganaye13-May-05 7:44 
GeneralRe: Closing on click is a problem. Pin
Anonymous14-May-05 2:18
sussAnonymous14-May-05 2:18 
GeneralRe: Closing on click is a problem. Pin
pascal ganaye14-May-05 6:05
memberpascal ganaye14-May-05 6:05 
GeneralClosing the PopMenu Pin
Bricoleu13-Apr-05 11:25
memberBricoleu13-Apr-05 11:25 
GeneralJust what I was looking for... Pin
Simmy_NJ14-Feb-05 3:59
memberSimmy_NJ14-Feb-05 3:59 
GeneralRe: Just what I was looking for... Pin
pascal ganaye14-Feb-05 7:57
memberpascal ganaye14-Feb-05 7:57 
GeneralRe: Just what I was looking for... Pin
Simmy_NJ14-Feb-05 12:00
memberSimmy_NJ14-Feb-05 12:00 
GeneralA suggestion for Popup Pin
Stumpy84211-Feb-05 13:13
memberStumpy84211-Feb-05 13:13 
GeneralRe: A suggestion for Popup Pin
pascal ganaye12-Feb-05 0:22
memberpascal ganaye12-Feb-05 0:22 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151002.1 | Last Updated 2 May 2005
Article Copyright 2005 by Pascal Ganaye
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid