2012-03-10 77 views
3

我正在写一个扩展的进度条控件,目前已经100%开放源代码,并且我已经创建了一些带有渐变和纯色的基本样式。动画栏中的进度条winform

我想添加的一个选项是动画到酒吧,prety很像Windows 7和Vista的绿色进度条。所以我需要向%栏添加一个移动的“发光”,但是我对此的尝试看起来很糟糕。

我的方法是绘制一个具有设置大小的椭圆,并移动它的x位置,直到动画开始再次到达终点。

首先有没有人有没有链接或代码,以帮助我使用GDI或类似的方法来实现当前的Windows 7发光效果?

我还有其他几个动画,它们也会被添加到GDI中。

private void renderAnimation(PaintEventArgs e) 
    { 
     if (this.AnimType == animoptions.Halo) 
     {     
      Rectangle rec = e.ClipRectangle; 
      Rectangle glow = new Rectangle(); 
      //SolidBrush brush = new SolidBrush(Color.FromArgb(100, Color.White)); 
      //int offset = (int)(rec.Width * ((double)Value/Maximum)) - 4; 
      int offset = (int)(rec.Width/Maximum) * Value; 

      if (this.animxoffset > offset) 
      { 
       this.animxoffset = 0; 
      } 
      glow.Height = rec.Height - 4; 
      if (this.animxoffset + glow.X > offset) 
      { 
       glow.Width = offset - (this.animxoffset + 50); 
      } 
      else 
      { 
       glow.Width = 50; 
      } 


      glow.X = this.animxoffset; 
      LinearGradientBrush brush = new LinearGradientBrush(glow, Color.FromArgb(0, Color.White), Color.FromArgb(100, Color.White), LinearGradientMode.Horizontal); 
      e.Graphics.FillEllipse(brush, this.animxoffset, 2, glow.Width, glow.Height); 
      brush.Dispose(); 

      string temp = offset.ToString(); 

      e.Graphics.DrawString(temp + " : " + glow.X.ToString(), DefaultFont, Brushes.Black, 2, 2); 


      animTimer = new System.Timers.Timer(); 
      animTimer.Interval = 10; 
      animTimer.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed); 
      animTimer.Start(); 
     } 
    } 
void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e) 
    { 
     this.animTimer.Stop(); 
     this.animxoffset += 2; 
     Invalidate(); 


    } 

回答

0

这只是一个迭代通过笔数组的示例辉光。 您也可以使用透明图像(尽管它可能会对性能产生影响)。

 Pen[] gradient = { new Pen(Color.FromArgb(255, 200, 200, 255)), new Pen(Color.FromArgb(150, 200, 200, 255)), new Pen(Color.FromArgb(100, 200, 200, 255)) }; 
     int x = 20; 
     int y = 20; 
     int sizex = 200; 
     int sizey = 10; 
     int value = 25; 


     //draw progress bar basic outline (position - 1 to compensate for the outline) 
     e.Graphics.DrawRectangle(Pens.Black, new Rectangle(x-1, y-1, sizex, sizey)); 

     //draw the percentage done 
     e.Graphics.FillRectangle(Brushes.AliceBlue, new Rectangle(x, y, (sizex/100)*value, sizey)); 

     //to add the glow effect just add lines around the area you want to glow. 
     for (int i = 0; i < gradient.Length; i++) 
     { 
      e.Graphics.DrawRectangle(gradient[i], new Rectangle(x - (i + 1), y - (i + 1), (sizex/100) * value + (2 * i), sizey + (2 * i))); 
     }