ExpandingIcon.cs :  » GUI » TreeViewAdv » Aga » Controls » Tree » NodeControls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » TreeViewAdv 
TreeViewAdv » Aga » Controls » Tree » NodeControls » ExpandingIcon.cs
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 volatile Thread _animatingThread;
        private static object _lock = new object();

    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()
    {
            lock (_lock)
            {
                if (_animatingThread == null)
                {
                    _index = 0;
                    _animatingThread = new Thread(new ThreadStart(IterateIcons));
                    _animatingThread.IsBackground = true;
                    _animatingThread.Priority = ThreadPriority.Lowest;
                    _animatingThread.Start();
                }
            }
    }

        public static void Stop()
        {
            lock (_lock)
            {
                _index = 0;
                _animatingThread = null;
            }
        }

    private static void IterateIcons()
    {
            while (_animatingThread != null)
      {
        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);
      }
            System.Diagnostics.Debug.WriteLine("IterateIcons Stopped");
    }

    public static event EventHandler IconChanged;
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.