|
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
namespace Aga.Controls.Tree.NodeControls
{
/// <summary>
/// Displays an animated icon for those nodes, who are in expanding state.
/// Parent TreeView must have AsyncExpanding property set to true.
/// </summary>
public class ExpandingIcon: NodeControl
{
private static GifDecoder _gif = ResourceHelper.LoadingIcon;
private static int _index = 0;
private static Thread _animatingThread;
public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
{
return ResourceHelper.LoadingIcon.FrameSize;
}
protected override void OnIsVisibleValueNeeded(NodeControlValueEventArgs args)
{
args.Value = args.Node.IsExpandingNow;
base.OnIsVisibleValueNeeded(args);
}
public override void Draw(TreeNodeAdv node, DrawContext context)
{
Rectangle rect = GetBounds(node, context);
Image img = _gif.GetFrame(_index).Image;
context.Graphics.DrawImage(img, rect.Location);
}
public static void Start()
{
_index = 0;
if (_animatingThread == null)
{
_animatingThread = new Thread(new ThreadStart(IterateIcons));
_animatingThread.IsBackground = true;
_animatingThread.Priority = ThreadPriority.Lowest;
_animatingThread.Start();
}
}
private static void IterateIcons()
{
while (true)
{
if (_index < _gif.FrameCount - 1)
_index++;
else
_index = 0;
if (IconChanged != null)
IconChanged(null, EventArgs.Empty);
int delay = _gif.GetFrame(_index).Delay;
Thread.Sleep(delay);
}
}
public static event EventHandler IconChanged;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Philip is a Software Architect with severaly years of experience. He studied business IT in the University of Wedel, Germany, and has reached his Masters degree in 2010. Back in 2002, he started his so far best-known software PDFCreator. The second developer joined two years later and since then, both constantly improve this piece of open source software.