开发者

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

开发者 https://www.devze.com 2023-04-02 07:05 出处:网络
I am working on a C# desktop application. I am using a menu strips control in which I have used a开发者_开发百科 drop down button.

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:

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

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.


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


You could possibly use a ComboBox control instead and change the DropDownStyle to DropDownList.

Some information on how to use a button with a ComboBox can be found here: http://social.msdn.microsoft.com/forums/en-US/winformsdesigner/thread/5d65f987-834c-465f-a944-622831d4cfb0

0

精彩评论

暂无评论...
验证码 换一张
取 消