[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ToolStripSplitButton does not close drop-down list when the arrow is clicked

Posted on 2016-09-15
2
Medium Priority
?
105 Views
Last Modified: 2016-09-15
Hi experts
I wonder how I could get a ToolStripSplitButton to behave the same as a Combobox when the arrow is clicked.

With a Combobox, click the arrow will open its drop-down list. Click it again will close the drop-down list.
With a ToolStripSplitButton. click the arrow will open its drop-down list (which is expected), but clicking the arrow again, the ToolStripSplitButton doesn't close the drop-down list (as in a combobox).

I am using VS2008, Winform, C#.

Thanks in advance
Dominic
0
Comment
Question by:dominicwong
2 Comments
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 2000 total points
ID: 41800879
I believe this control was created with this behavior for a reason. And myself I don't like to change behavior for standard controls. However, you may try the following code. Honestly, not sure how robust it is :).

You may need to add event handlers to your project...

namespace ToolStripTest
{
    public partial class Form1 : Form
    {

        private bool isClickedToOpen = false;
        public Form1()
        {
            InitializeComponent();
        }

        private void toolStripSplitButton1_Click(object sender, EventArgs e)
        {
            if (isClickedToOpen)
            {
                toolStripSplitButton1.HideDropDown();
            }

            isClickedToOpen  = !isClickedToOpen ;
            System.Diagnostics.Debug.WriteLine("Click");
        }

        private void toolStripSplitButton1_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            isClickedToOpen = !isClickedToOpen;
        }

        private void toolStripSplitButton1_ButtonClick(object sender, EventArgs e)
        {
            isClickedToOpen = false;
            System.Diagnostics.Debug.WriteLine("ButtonClick");
        }
    }
}[/code]
0
 

Author Closing Comment

by:dominicwong
ID: 41800938
Thanks anarki_jimbel.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month18 days, 19 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question