3
具体来说,我正在做的是使我的System.Windows.Forms.TreeView控件中的节点的图标在长时间加载操作发生时跳动。在C#中做事情的最佳方式是什么?
具体来说,我正在做的是使我的System.Windows.Forms.TreeView控件中的节点的图标在长时间加载操作发生时跳动。在C#中做事情的最佳方式是什么?
如果将每个帧加载到ImageList中,则可以使用循环更新为每个帧。 例子:
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(); }
显然有不止几个方式来实现这一点,但这里的基本思想。
再看一遍,您应该在增加图像索引之前,确实检查图像索引是否在imagelist.images计数的范围内。 – 2008-09-13 03:19:53