Click here to Skip to main content
15,881,600 members
Articles / Programming Languages / C#

Super Context Menu Strip

Rate me:
Please Sign up or sign in to vote.
4.77/5 (51 votes)
5 Oct 2009CPOL2 min read 195.7K   10K   224  
How to build a context menu that displays any group of controls
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;


namespace SuperContextMenu
{
    public partial class PopedCotainer : UserControl
    {
        public PopedCotainer()
        {
            InitializeComponent();
        }


        protected override bool ProcessDialogKey(Keys keyData)
        {// Alt+F4 is to closing
            if ((keyData & Keys.Alt) == Keys.Alt)
                if ((keyData & Keys.F4) == Keys.F4)
                {
                    this.Parent.Hide();
                    return true;
                }
            
            if ((keyData & Keys.Enter) == Keys.Enter)
            {
                if (this.ActiveControl is Button)
                {
                    (this.ActiveControl as Button).PerformClick();
                    return true;
                }
            }
            
            return base.ProcessDialogKey(keyData);
        }

  

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions