2012-03-10 78 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))); 
     }