Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure ToolStripDropdownbutton size to match size of the parent dropdown button?

Tags:

c#

.net

windows

I am working on a C# desktop application. I am using a menu strips control in which I have used a drop down button.

Whenever the dropdown is clicked, it displays items, but the Width of the Dropdown Menu seems to be the issue, it's always greater. I want it to be the same size at that of the button.

Here is a screenshot:

Screenshot

What I am struggling to configure:

  1. I want the width of DropDown to be the same as that of button.
  2. The arrow of the dropdown should be larger.
  3. The button should be curvy, not flat styled, it's a ToolStripDropdownbutton.
like image 682
Gaurav Agrawal Avatar asked Sep 05 '11 13:09

Gaurav Agrawal


1 Answers

Unfortunately you are going against the grain for this control, and you will need to resort to your own controls or custom painting to get exactly what you want.

You should be able to change the shape/size of the drop down arrow using custom painting. You should be able to restrict the size of the drop down menu by overriding the control. However as the drop down menu has space for ticks and shortcut strings I suspect you may need to do more work than you were expecting.

Here are a couple of pointers that you may find helpful: http://connect.microsoft.com/VisualStudio/feedback/details/97456/owner-drawn-toolstripcombobox

This suggests using the ToolStripControlHost(control) to host arbitrary controls. With a simple example at: http://alala666888.wordpress.com/2010/07/15/custom-toolstripitem/

http://www.codeproject.com/KB/static/DropDownContainer.aspx This project (albeit in VB.Net) shows many of the issues with writing your own controls to do the same thing.

There is also this article about writing ToolStripRenderers: http://www.codeproject.com/KB/menus/CustomToolStripRenderer.aspx

Here's another C# based example of a custom control: http://www.codeproject.com/KB/selection/office2003colorpicker.aspx

like image 61
StephenD Avatar answered Oct 03 '22 16:10

StephenD