2012-03-10 22 views
3

現在、100%オープンソースの拡張プログレスバーコントロールを作成しています。グラデーションとソリッドカラーの基本スタイルをいくつか作成しました。進捗バーのwinformバー

私が追加したいオプションの1つは、バーにアニメーションを加えたものです。ウィンドウズ7とビスタグリーンのプログレスバーとほとんど同じです。だから私は%バーに移動 "グロー"を追加する必要がありますが、これで私の試みはひどいです。

私の方法は、サイズが設定された楕円を描き、アニメーションが再び開始するまでにx位置に移動することです。

最初に誰かが、GDIや他の同様の方法を使って現在のウィンドウ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))); 
     } 
関連する問題