我正在尝试重现Control Expander WPF
的操作,或者如Outlook
,Vertical Web Menu
等菜单中所示,因为在WindowsForms
中此控件没有存在。在这里,我保留sample code: Menu_Expader.zip链接 GoogleDrive 。
我已设法使用以下控件执行此操作:
Panels
FlowLayoutPanel
1 Time Control
Button Vectors
Labels Vectors
... 这完美无缺,但我必须在每个面板上建立一个
Maximum Size
和Minimum 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; }
彼此非常接近对用户的愿景有点恼火。
示例这就是我目前所拥有的:
代码示例:
quantity
我想得到与此类似的结果 - Bootstrap Menu Accordion:
模仿操作面板根据其包含的
item
scroll bar
展开,只要它不从屏幕突出,在这种情况下它会显示DVexpress
。我知道有些软件可以提供DotNetBar Suite
,Licensed Software
等自定义控件,但它们是pirate
我不想非法使用它#some-class.bbclass PROC ??= ""
。 您能帮我优化或以其他方式创建吗?
环境:Visual Studio 2010&amp; .NET NetFramework 4。
original question我用西班牙语在StackOverFlow中创建了它。
注意:如果有人说西班牙语和英语并且可以做更好的翻译,请编辑问题。 (请原谅图片上的广告,我用软件试用版录制了屏幕)。