Example #1
0
        // 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();
        }
Example #2
0
 /// <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();
 }
Example #3
0
 /// <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();
 }
Example #4
0
 /// <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();
 }
Example #5
0
 /// <summary>
 /// Select an item and perform tha animation as on click.
 /// </summary>
 /// <param name="item"></param>
 public void SelectItemWithAnimation(AccordionItem item)
 {
     Animate(item);
 }
Example #6
0
 /// <summary>
 /// Clear all accordion items.
 /// </summary>
 public void ClearAccordion()
 {
     Controls.Clear();
     SelectedItem = null;
     Redraw();
 }
Example #7
0
        // 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();
        }
Example #8
0
 /// <summary>
 /// Select an item and perform tha animation as on click.
 /// </summary>
 /// <param name="item"></param>
 public void SelectItemWithAnimation(AccordionItem item)
 {
     Animate(item);
 }
Example #9
0
 /// <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();
 }
Example #10
0
 /// <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();
 }