C# Programming > Forms

C# Drop-Down Dialog

c# drop-down dialog

Dialogs in C#

C#.NET does not come with clear-cut for a dialog-box. That's because all Windows Forms can be dialog-boxes. There is no limit to the different types of .Net dialog-boxes that you can program in C#.

In this article we'll create an advanced dialog-box that will behave like a drop-down menu. The applications for it are equally limitless. For example, a custom color-picker, a user-drawn menu, an advanced selection control, etc.

Drop-Down Behavior

First you must establish the behavior of a C# drop-down control.

  • No titlebar, but still has a border
  • Closes if the mouse clicks anywhere outside its bounds
  • Does not show up on the taskbar
  • Is on top of all other controls

To remove the titlebar from a Form while keeping the border, refer to the Titlebar-less Form article. It takes a couple lines of C# code.

To keep track of when the mouse clicks, make use of the OnMouseDown event. The trick is to set the following property to the dialog:

frmDialog.Capture = true;

Which will tell the C# window to keep track of the mouse cursor even when it clicks on things outside your C# program.

Finally, to hide a program from the taskbar set the ShowInTaskbar property and to make the dialog stay on top set TopMost to true.

The sample program can be downloaded at the bottom of the page. Download it and see a working drop-down dialog in C#...

Back to C# Article List