Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6899855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:28:27+00:00 2026-05-27T07:28:27+00:00

I am trying to mimic the behavior of, for example, Windows Explorer and how

  • 0

I am trying to mimic the behavior of, for example, Windows Explorer and how the Favorites items can launch a context menu.

I currently am using:

contextMenu.Show((sender as ToolStripMenuItem).GetCurrentParent().PointToScreen(e.Location));

This occurs in the MouseDown event of the ToolStripMenuItem. The problem is that the menu closes immediately after right-click, and I don’t know any way to suspend it while the context menu is open.

I’ve tried deriving from ToolStripMenuItem and overriding the MouseDown/MouseUp but I can’t figure out how to keep it open on click.

Is there a good way of doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:28:27+00:00Added an answer on May 27, 2026 at 7:28 am

    One way that you could accomplish this is by using the ToolStripDropDown control to host a ListBox inside of the ToolStripDropDown.

    This may require some tweaking regarding the AutoClose behavior, but it should get you started:

    First in your main form, add the following line to your ToolStripDropDropDown item

    toolStripDropDownButton1.DropDown = new CustomListDropDown();
    

    Then create a custom drop down class as follows:

    public class CustomListDropDown : ToolStripDropDown
    {
        private ContextMenuStrip contextMenuStrip1;
        private ToolStripMenuItem toolStripMenuItem1;
        private ToolStripMenuItem toolStripMenuItem2;
        private ToolStripMenuItem toolStripMenuItem3;
        private System.ComponentModel.IContainer components;
    
        public ListBox ListBox { get; private set; }
    
        public CustomListDropDown()
        {
            InitializeComponent();
    
            this.ListBox = new ListBox() { Width = 200, Height = 600 };
            this.Items.Add(new ToolStripControlHost(this.ListBox));
    
            this.ListBox.ContextMenuStrip = contextMenuStrip1;
            this.ListBox.MouseDown += new MouseEventHandler(ListBox_MouseDown);
    
            contextMenuStrip1.Closing += new ToolStripDropDownClosingEventHandler(contextMenuStrip1_Closing);
    
            //add sample items
            this.ListBox.Items.Add("Item1");
            this.ListBox.Items.Add("Item2");
            this.ListBox.Items.Add("Item3");
            this.ListBox.Items.Add("Item4");
        }
    
        void contextMenuStrip1_Closing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            this.Close();
            this.AutoClose = true;
        }
    
        void ListBox_MouseDown(object sender, MouseEventArgs e)
        {
            this.AutoClose = false;
            this.ListBox.SelectedIndex = this.ListBox.IndexFromPoint(e.Location);
        }
    
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem();
            this.contextMenuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // contextMenuStrip1
            // 
            this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripMenuItem1,
            this.toolStripMenuItem2,
            this.toolStripMenuItem3});
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            // 
            // contextMenuStrip1.ContextMenuStrip
            // 
            this.contextMenuStrip1.Size = new System.Drawing.Size(181, 48);
            // 
            // toolStripMenuItem1
            // 
            this.toolStripMenuItem1.Name = "toolStripMenuItem1";
            this.toolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
            this.toolStripMenuItem1.Text = "toolStripMenuItem1";
            // 
            // toolStripMenuItem2
            // 
            this.toolStripMenuItem2.Name = "toolStripMenuItem2";
            this.toolStripMenuItem2.Size = new System.Drawing.Size(180, 22);
            this.toolStripMenuItem2.Text = "toolStripMenuItem2";
            // 
            // toolStripMenuItem3
            // 
            this.toolStripMenuItem3.Name = "toolStripMenuItem3";
            this.toolStripMenuItem3.Size = new System.Drawing.Size(180, 22);
            this.toolStripMenuItem3.Text = "toolStripMenuItem3";
            // 
            // CustomListDropDown
            // 
            this.Size = new System.Drawing.Size(2, 4);
            this.contextMenuStrip1.ResumeLayout(false);
            this.ResumeLayout(false);
    
        }
    }
    

    In my tests this worked reasonably well. Let me know how it goes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to mimic template behavior in C++ using macros. For instance, if
I'm trying to mimic something similar to FB. Basically, users can post comments in
Using this site as a reference. Trying to mimic this effect using JavaScript, hover
I'm trying to mimic the coverflow UI here: jsFiddle As you can see on
For (auto-)educational purposes, I'm trying to mimic the super behavior to learn how it
I am trying to use geom_ribbon to mimic the behavior of geom_area but i
I am trying to mimic UINavigationController's pushViewController using UIView animation but I have seem
I'm trying to mimic the login page from the example http://tipfy-auth.appspot.com (source http://code.google.com/p/tipfy/source/browse/examples/auth/app/ )
I am trying to mimic the Sticky Notes application in Windows 7. In the
I'm trying to mimic the webforms multiview functionality and the only way i can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.