C#中的Expander菜单

时间:2018-01-11 18:15:57

标签: c# winforms menu panel

我正在尝试重现Control Expander WPF的操作,或者如OutlookVertical Web Menu等菜单中所示,因为在WindowsForms中此控件没有存在。在这里,我保留sample code: Menu_Expader.zip链接 GoogleDrive

我已设法使用以下控件执行此操作:

  • Panels
  • FlowLayoutPanel
  • 1 Time Control
  • Button Vectors
  • Labels Vectors ...
  

这完美无缺,但我必须在每个面板上建立一个    Maximum SizeMinimum Size因此,每当我在item内添加item时,我必须修改我添加它的面板的大小,并且 // The state of an expanding or collapsing panel. private enum ExpandState { Expanded, Expanding, Collapsing, Collapsed, } // The expanding panels' current states. private ExpandState[] ExpandStates; // The Panels to expand and collapse. private Panel[] ExpandPanels; // The expand/collapse buttons. private Button[] ExpandButtons; // Initialize. private void Form1_Load(object sender, EventArgs e) { // Initialize the arrays. ExpandStates = new ExpandState[] { ExpandState.Expanded, ExpandState.Expanded, ExpandState.Expanded, }; ExpandPanels = new Panel[] { panModule1, panModule2, panModule3, }; ExpandButtons = new Button[] { btnExpand1, btnExpand2, btnExpand3, }; // Set expander button Tag properties to give indexes // into these arrays and display expanded images. for (int i = 0; i < ExpandButtons.Length; i++) { ExpandButtons[i].Tag = i; ExpandButtons[i].Image = Properties.Resources.expander_down; } } // Start expanding. private void btnExpander_Click(object sender, EventArgs e) { // Get the button. Button btn = sender as Button; int index = (int)btn.Tag; // Get this panel's current expand // state and set its new state. ExpandState old_state = ExpandStates[index]; if ((old_state == ExpandState.Collapsed) || (old_state == ExpandState.Collapsing)) { // Was collapsed/collapsing. Start expanding. ExpandStates[index] = ExpandState.Expanding; ExpandButtons[index].Image = Properties.Resources.expander_up; } else { // Was expanded/expanding. Start collapsing. ExpandStates[index] = ExpandState.Collapsing; ExpandButtons[index].Image = Properties.Resources.expander_down; } // Make sure the timer is enabled. tmrExpand.Enabled = true; } // The number of pixels expanded per timer Tick. private const int ExpansionPerTick = 7; // Expand or collapse any panels that need it. private void tmrExpand_Tick(object sender, EventArgs e) { // Determines whether we need more adjustments. bool not_done = false; for (int i = 0; i < ExpandPanels.Length; i++) { // See if this panel needs adjustment. if (ExpandStates[i] == ExpandState.Expanding) { // Expand. Panel pan = ExpandPanels[i]; int new_height = pan.Height + ExpansionPerTick; if (new_height >= pan.MaximumSize.Height) { // This one is done. new_height = pan.MaximumSize.Height; } else { // This one is not done. not_done = true; } // Set the new height. pan.Height = new_height; } else if (ExpandStates[i] == ExpandState.Collapsing) { // Collapse. Panel pan = ExpandPanels[i]; int new_height = pan.Height - ExpansionPerTick; if (new_height <= pan.MinimumSize.Height) { // This one is done. new_height = pan.MinimumSize.Height; } else { // This one is not done. not_done = true; } // Set the new height. pan.Height = new_height; } } // If we are done, disable the timer. tmrExpand.Enabled = not_done; } 彼此非常接近对用户的愿景有点恼火。

示例这就是我目前所拥有的:

enter image description here

修改

代码示例:

quantity

我想得到与此类似的结果 - Bootstrap Menu Accordion:

enter image description here

  

模仿操作面板根据其包含的item scroll bar展开,只要它不从屏幕突出,在这种情况下它会显示DVexpress。我知道有些软件可以提供DotNetBar SuiteLicensed Software等自定义控件,但它们是pirate我不想非法使用它#some-class.bbclass PROC ??= "" 您能帮我优化或以其他方式创建吗?

环境:Visual Studio 2010&amp; .NET NetFramework 4。

  

original question我用西班牙语在StackOverFlow中创建了它。

  • Modulo(模块)
  • 菜单主体(主菜单)
  • Mantenimientos(维护)
  • 处理(流程)
  • 咨询(查询)
  • 报告(报告)

注意:如果有人说西班牙语和英语并且可以做更好的翻译,请编辑问题。 (请原谅图片上的广告,我用软件试用版录制了屏幕)。

0 个答案:

没有答案