Pergunta

Especificamente, o que pretendo fazer é fazer com que os ícones dos nós em meu controle System.Windows.Forms.TreeView latejem enquanto uma longa operação de carregamento está ocorrendo.

Foi útil?

Solução

Se você carregar cada quadro em um ImageList, poderá usar um loop para atualizar cada quadro.Exemplo:

    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();
    }

Obviamente, existem mais do que algumas maneiras de implementar isso, mas aqui está a ideia básica.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top