问题描述
大家好,
我有个问题.我有一个MDI Windows窗体应用程序.我正在将VS2008 Express SP1与.NET 3.5 SP1和Windows Forms 2.0一起使用.
我真的很困惑,甚至不确定这是否可能.在父窗口上,我已将工具栏停靠在菜单栏下方的顶部.
现在,我知道您可以通过调用ToolStripManager.Merge()合并两个ToolStrip(就像菜单一样).我的问题是,我在父窗口的ToolStrip上有一个ToolStripComboBox,当没有打开MDI窗口时,我将其禁用了.不必编写冗长的UI更新代码,因为我有多种类型的子表单(用于多种文档类型),并且我只希望在打开某种类型的子窗口时启用组合框.
所以我的想法是,使用VS2008表单设计器中的编辑"->复制",复制并粘贴组合框,以便它现在位于子表单以及主窗口上的ToolStrip上,但是这次是子窗口窗体的ToolStripComboBox已启用. ToolStripComboBox的DropDownStyle是DropDownList,所以很遗憾,我无法设置Text属性,这是我可以通过MergeAction.Replace匹配项目的方式,从而在子窗口时将禁用的ToolStripComboBox替换为子窗口启用的ToolStripComboBox是打开的,然后在我关闭所有该类型的子窗口时将禁用的框放回去.
但是我试过在两个ToolStripComboBox上都使用MergeAction.Replace,但无济于事.我被困住了.
Hello all,
I have a question. I have a MDI Windows Forms application. I am using VS2008 Express SP1 with .NET 3.5 SP1 and Windows Forms 2.0.
I am really puzzled and not even sure if this is even possible. on the parent window, i have docked a ToolStrip to the top, below the menu bar.
Now, I know you can merge two ToolStrips (just like menus) with a call to ToolStripManager.Merge(). My problem is, I have a ToolStripComboBox on the parent window''s ToolStrip and I have it disabled when no MDI windows are open. Instead of have to write hairy UI update code, because I have multiple types of child forms (for multiple document types) and I only want the combo box to be enabled for when a certain type of child window is open.
So my thought was to, using Edit->Copy in the VS2008 form designer, copy and paste the combo box so it''s now on a ToolStrip on the child form as well as the main window, and this time though, the child form''s ToolStripComboBox is enabled. The DropDownStyle of the ToolStripComboBox is DropDownList, so unfortunately, I cannot set the Text property, which would be the way I can match items with MergeAction.Replace and thus replace the disabled ToolStripComboBox with the child window''s enabled ToolStripComboBox when the child window is open and then put the disabled box back when I close all child windows of that type.
But I''ve tried using MergeAction.Replace on both ToolStripComboBox''s with no avail. I''m stuck. Does anyone have any ideas or suggestions?
推荐答案
我在父窗口的ToolStrip上有一个ToolStripComboBox,当没有打开MDI窗口时我将其禁用.不必写冗长的UI更新代码,因为我有多种类型的子窗体(用于多种文档类型),并且我只希望在打开某种类型的子窗口时启用组合框.
I have a ToolStripComboBox on the parent window''s ToolStrip and I have it disabled when no MDI windows are open. Instead of have to write hairy UI update code, because I have multiple types of child forms (for multiple document types) and I only want the combo box to be enabled for when a certain type of child window is open.
当然,这似乎表明组合框的适当位置是子窗口.有没有可能的原因?
通常,当我遇到一些过于混乱和复杂的内容时,这意味着该是重新考虑总体策略的时候了.不过,我不确定您是否还有其他考虑事项.
That certainly seems to indicate that the proper place for the combo-box is the child window. Is there a reason that''s not possible?
Usually when I run into stuff that gets too convoluted and complex, it means it''s time to rethink the overall strategy. I''m not sure if there are other considerations in your case, though.
这篇关于使用MergeAction.Replace替换合并的ToolStrip上的ToolStripComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!