对于动态添加ToolStripItems变化的ToolStripPanel溢出行为 [英] Change ToolStripPanel overflow behavior for dynamically added ToolStripItems

查看:137
本文介绍了对于动态添加ToolStripItems变化的ToolStripPanel溢出行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体的ToolStripPanel我动态添加新的ToolStrips给它。每个ToolStrip的有ToolStripItems,我动态地添加到它(主要是ToolStripButtons)。

I have a Windows Forms ToolStripPanel that I dynamically add new ToolStrips to it. Each ToolStrip has ToolStripItems that I dynamically add to it (mostly ToolStripButtons).

我想所有的ToolStrips适合在一个行,只要你可以看到每个ToolStrip的所有ToolStripItems。如果添加新的ToolStripItem到ToolStrip的产生溢出发生,我想ToolStrip的,在该行的末尾跳转到一个新行。唯一一次我想看到溢出按钮,如果ToolStrip的都有,他们不适合在表格的宽度这么多项目。

I would like to have all the ToolStrips fit on one row as long as you can see all the ToolStripItems in each ToolStrip. If adding a new ToolStripItem to a ToolStrip causes overflow to occur, I'd like the ToolStrip at the end of the row to jump down to a new row. The only time I'd like to see the overflow button is if the ToolStrip has so many items that they can't fit on the width of the form.

我想这是默认的行为,除非用户手动移动一个ToolStrip的。如果用户移动ToolStrip的,那么我想现有的溢出(如溢出按钮的下拉选项)的行为发生。我假设用户将与此默认的WinForms溢出的行为确定的,如果他们定位自己的工具栏。

I want this to be the default behavior unless a user manually moves a ToolStrip. If the user moves the ToolStrip, then I want the existing overflow (e.g. overflow button with drop down choices) behavior to occur. I assume the user will be OK with this default Winforms overflow behavior if they position the toolbar themselves.

如果一个新的动态工具栏添加的用户重新定位后的事情,我想新的工具栏添加到最后的ToolStrip的最下面一行的权利。该工具栏应该有更新的溢出行为(例如使用新行,如果你不适合),直到用户手动重新定位它。

If a new dynamic toolbar is added after the user repositions things, I'd like the new toolbar to be added to the right of the last ToolStrip in the bottom row. This toolbar should have the updated overflow behavior (e.g. use a new row if you can't fit) until the user manually repositions it.

我已经没有很大的成功做了一些研究:

I've done some research without great success:

  • 这似乎是它应该是改变的 ToolStripLayoutStyle ,但是这似乎并不如此。 (在最好的情况,都是当溢出按钮被显示在所有ToolStrips一个给定行中创建新行)。
  • 在MSDN文章如何管理的ToolStrip溢出在Windows窗体似乎当溢出按钮时,只遮挡/。
  • 有一个 LayoutCompleted 事件上,似乎可以用它来调整的事情ToolStrip的,好像应该有一个更简单的方法。
  • <一个href="http://stackoverflow.com/questions/403769/trying-to-add-a-toolstrip-to-a-toolstrippanel-side-by-side-with-an-existing-tools">Creating自定义LayoutEngine 似乎是由于内置在一个非常接近我想要做的。
  • 此矫枉过正
  • This seems like it should be a simple matter of changing a ToolStripLayoutStyle, but this doesn't seem to be the case. (At best, new rows are created when the overflow button is showing on all ToolStrips in a given row).
  • The MSDN article "How to: Manage ToolStrip Overflow in Windows Forms" seems to only cover if/when the overflow button occurs.
  • There is a LayoutCompleted event on the ToolStrip that seems possible to use to tweak things, it seems like there should be an easier way.
  • Creating a custom LayoutEngine seems like an overkill for this since the built-in one is very close to what I want to do.

我失去了一个简单的解决方案?

Am I missing an easy solution?

更新:还在寻找一个很好的解决方案。似乎LayoutCompleted路由是可能的。它存在的问题是,虽然它被多次调用。有一次,它说的ToolStripItem在溢出区和后立即在主区域,所以它似乎并不安全,只检查一次,如果它在溢出。

UPDATE: Still looking for a good solution. It seems the LayoutCompleted route is possible. The problem with it though is that it is called multiple times. One time it says the ToolStripItem is in the overflow area and immediately after that is in the Main area, so it doesn't seem safe to just check one time if it's in overflow.

推荐答案

在最后,我不认为这是一个好简单的解决方案。 <一href="http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/c6b66dba-0da0-451e-868e-d921c4d563db/"相对=nofollow>这个线程明确指出ToolStrips并没有真正专为动态场景为优先。

In the end, I don't think there is a good easy solution. This thread makes it clear that ToolStrips weren't really designed for dynamic scenarios as a priority.

一种独特的方法是设置ToolStrip的的<一个href="http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/c6b66dba-0da0-451e-868e-d921c4d563db/"相对=nofollow> 中的minimumSize是所有按钮的大小。这将开始溢出工作像我形容,但即使这样有问题的边缘情况。

One unique approach is to set the ToolStrip's MinimumSize to be the size of all the buttons. This will start to work with overflow like I describe, but even this has problems with edge cases.

我已经找到了最好的办法就是尽一切可能得到一个好的感受一下工具栏的大小应提前,然后使用的加入方法。如果你把时间提前一个合理的猜测,那么它可能确定如果您以后添加更多的按钮,因为他们最终会在溢出区域。

The best approach I've found is to do everything possible to get a good feel for what the size of the toolbar should be in advance and then position it on the ToolStripPanel using the Join method. If you make a reasonable guess ahead of time, then it's probably ok if you add more buttons later as they'll end up in the overflow area.

这篇关于对于动态添加ToolStripItems变化的ToolStripPanel溢出行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆