Added the source code of Aga.Controls (TreeViewAdv for .Net) version 1.7.0.0.
2 using System.Collections.Generic;
5 using System.Threading;
6 using System.Windows.Forms;
8 namespace Aga.Controls.Tree.NodeControls
11 /// Displays an animated icon for those nodes, who are in expanding state.
12 /// Parent TreeView must have AsyncExpanding property set to true.
14 public class ExpandingIcon: NodeControl
16 private static GifDecoder _gif = ResourceHelper.LoadingIcon;
17 private static int _index = 0;
18 private static volatile Thread _animatingThread;
19 private static object _lock = new object();
21 public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
23 return ResourceHelper.LoadingIcon.FrameSize;
26 protected override void OnIsVisibleValueNeeded(NodeControlValueEventArgs args)
28 args.Value = args.Node.IsExpandingNow;
29 base.OnIsVisibleValueNeeded(args);
32 public override void Draw(TreeNodeAdv node, DrawContext context)
34 Rectangle rect = GetBounds(node, context);
35 Image img = _gif.GetFrame(_index).Image;
36 context.Graphics.DrawImage(img, rect.Location);
39 public static void Start()
43 if (_animatingThread == null)
46 _animatingThread = new Thread(new ThreadStart(IterateIcons));
47 _animatingThread.IsBackground = true;
48 _animatingThread.Priority = ThreadPriority.Lowest;
49 _animatingThread.Start();
54 public static void Stop()
59 _animatingThread = null;
63 private static void IterateIcons()
65 while (_animatingThread != null)
67 if (_index < _gif.FrameCount - 1)
72 if (IconChanged != null)
73 IconChanged(null, EventArgs.Empty);
75 int delay = _gif.GetFrame(_index).Delay;
78 System.Diagnostics.Debug.WriteLine("IterateIcons Stopped");
81 public static event EventHandler IconChanged;