// Animate accordion private void Animate(AccordionItem to_select) { // Animation if ((SelectedItem != null) && (to_select != null) && (Controls.Count > 1)) { if ((SelectedItem != to_select)) { try { int prev_height = SelectedItem.Height; int sel_h_f = Math.Max(MinimumContentHeight + 24, this.Height - 25 * (Controls.Count - 1)); for (int sel_h_g = sel_h_f / 10; sel_h_g < sel_h_f - sel_h_f / 10; sel_h_g += sel_h_f / 10) { int y = 0; foreach (AccordionItem item in Controls) { int height = (item == to_select) ? sel_h_g + 24 : 24; if (item == SelectedItem) { height = prev_height - sel_h_g; } item.SetBounds(0, y, this.Width, height); y += height + 1; } Application.DoEvents(); System.Threading.Thread.Sleep(7); } } catch { } } } // Select item and redraw SelectedItem = to_select; Redraw(); }
/// <summary> /// Add an item in the accordion control. /// </summary> /// <param name="item">Item to add</param> public void AddAccordionItem(AccordionItem item) { item.Click += delegate { Animate(item); }; // Animation on click Controls.Add(item); if (Controls.Count == 1) SelectedItem = (AccordionItem)Controls[0]; Redraw(); }
/// <summary> /// Add an item in the accordion control. /// </summary> /// <param name="item">Item to add</param> public void AddAccordionItem(AccordionItem item) { item.Click += delegate { Animate(item); }; // Animation on click Controls.Add(item); if (Controls.Count == 1) { SelectedItem = (AccordionItem)Controls[0]; } Redraw(); }
/// <summary> /// Remove an item from the accordion control. /// </summary> /// <param name="item">Item to remove</param> public void RemoveAccordionItem(AccordionItem item) { if (SelectedItem == item) { SelectedItem = null; } Controls.Remove(item); if (SelectedItem == null && Controls.Count > 0) { SelectedItem = (AccordionItem)Controls[0]; } Redraw(); }
/// <summary> /// Select an item and perform tha animation as on click. /// </summary> /// <param name="item"></param> public void SelectItemWithAnimation(AccordionItem item) { Animate(item); }
/// <summary> /// Clear all accordion items. /// </summary> public void ClearAccordion() { Controls.Clear(); SelectedItem = null; Redraw(); }
// Animate accordion private void Animate(AccordionItem to_select) { // Animation if ((SelectedItem != null) && (to_select != null) && (Controls.Count > 1)) if ((SelectedItem != to_select)) try { int prev_height = SelectedItem.Height; int sel_h_f = Math.Max(MinimumContentHeight + 24, this.Height - 25 * (Controls.Count - 1)); for (int sel_h_g = sel_h_f / 10; sel_h_g < sel_h_f - sel_h_f / 10; sel_h_g += sel_h_f / 10) { int y = 0; foreach (AccordionItem item in Controls) { int height = (item == to_select) ? sel_h_g + 24 : 24; if (item == SelectedItem) height = prev_height - sel_h_g; item.SetBounds(0, y, this.Width, height); y += height + 1; } Application.DoEvents(); System.Threading.Thread.Sleep(7); } } catch { } // Select item and redraw SelectedItem = to_select; Redraw(); }
/// <summary> /// Remove an item from the accordion control. /// </summary> /// <param name="index">Index of the item to remove</param> public void RemoveAccordionItemAt(int index) { if (SelectedItem == Controls[index]) SelectedItem = null; Controls.RemoveAt(index); if (SelectedItem == null && Controls.Count > 0) SelectedItem = (AccordionItem)Controls[0]; Redraw(); }
/// <summary> /// Remove an item from the accordion control. /// </summary> /// <param name="item">Item to remove</param> public void RemoveAccordionItem(AccordionItem item) { if (SelectedItem == item) SelectedItem = null; Controls.Remove(item); if (SelectedItem == null && Controls.Count > 0) SelectedItem = (AccordionItem)Controls[0]; Redraw(); }