由于工作需要,我要在TreeView控件的第一结点前面加一图标,而且要使之闪烁。
我使用一Timer控件,一全局boolean型变量FlashIcon,在Timer1的OnTimer事件加入以下代码:
procedure TfrmMainSer.OnTimer(Sender: TObject);
begin
         FlashIcon := not FlashIcon;
         if FlashIcon then
            TreeViewRoom.Items[0].ImageIndex := -1 //去掉图标
         else
            TreeViewRoom.Items[0].ImageIndex := 0;//加入图标
end;
TreeView控件问题:为什么执行下面一段代码之后,TreeView控件会有闪烁的现象???
帮个忙?帮个忙?帮个忙?帮个忙?帮个忙?帮个忙?帮个忙?帮个忙?帮个忙?
100分相送!100分相送!100分相送!100分相送!100分相送!100分相送!

解决方案 »

  1.   

    在更新图标前加上:TreeView1.Items.BeginUpdate;
    更新图标后加上:TreeView1.Items.EndUpdate;
      

  2.   

    好象用TIMER都得闪一下子的:)
      

  3.   

    我帮你解决了,这样就不会了啦,可能是你刷新区域太大了,所以会闪烁procedure TForm1.Timer1Timer(Sender: TObject);
    var
      Rect: TRect;
    begin
      FlashIcon := not FlashIcon;
      if FlashIcon then
        TreeViewRoom.Items[0].ImageIndex := -1 //去掉图标
      else
        TreeViewRoom.Items[0].ImageIndex := 0;//加入图标
      TreeViewRoom.Update;
      Rect := TreeViewRoom.Items[0].DisplayRect(false);
      InvalidateRect(TreeViewRoom.Handle, @Rect, false);
    end;
      

  4.   

    TreeViewRoom.Update;不要,注释掉
      

  5.   

    我觉得geyobing(银翼天使) 的方法可以一试
      

  6.   

    Invalidate 这个函数通知控件它的整个表面将要被重画,调用该函数可在有效的防止在以后的多次的重画中,避免控件的闪烁。而且在实际重画前多次调用这个函数并不会引起性能上的损失。Invalidate informs a control that its entire surface needs to be repainted. Calling Invalidate can prevent flicker caused by a series of partial repaints. There is no performance penalty for calling Invalidate multiple times before the control is actually repainted.