Question

Specifically what I am looking to do is make the icons for the Nodes in my System.Windows.Forms.TreeView control to throb while a long loading operation is taking place.

Was it helpful?

Solution

If you load each frame into an ImageList, you can use a loop to update to each frame. Example:

    bool runThrobber = true;
    private void AnimateThrobber(TreeNode animatedNode)
    {
        BackgroundWorker bg = new BackgroundWorker();
        bg.DoWork += new DoWorkEventHandler(delegate
        {
            while (runThrobber)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    animatedNode.SelectedImageIndex++;
                    if (animatedNode.SelectedImageIndex >= imageList1.Images.Count) > animatedNode.SelectedImageIndex = 0;
                });
                Thread.Sleep(100);
            }
        });
        bg.RunWorkerAsync();
    }

Obviously there's more than a few ways to implement this, but here's the basic idea.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top