title: C# - Gradient over picture in picturebox
body: <p>I have developed an application in VB.NET that I'm now moving over to C#.</p>
  
  <p>Everything is going smooth so far, but I'm facing one problem.</p>
  
  <p>I have a pictureBox that has a picture in it. Over this picture box I want a gradient to be that goes from transparent at top down to the color "control" to blend in with the forms background color. I have allready done this in VB.net which works, but when im trying to do this in C# the gradient seems to be drawn, but behind the picture.</p>
  
  <p>Here is what i have tried:</p>
  
  <pre><code>private void PictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
  {
      Color top = Color.Transparent;
      Color bottom = Color.FromKnownColor(KnownColor.Control);
  
      GradientPictureBox(top, bottom, ref PictureBox1, e);
  }
  
  public void GradientPictureBox(Color topColor, Color bottomColor, ref PictureBox PictureBox1, System.Windows.Forms.PaintEventArgs e)
  {
      LinearGradientMode direction = LinearGradientMode.Vertical;
      LinearGradientBrush brush = new LinearGradientBrush(PictureBox1.DisplayRectangle, topColor, bottomColor, direction);
      e.Graphics.FillRectangle(brush, PictureBox1.DisplayRectangle);
      brush.Dispose();
  }   
  </code></pre>
  
  <p>However this does in fact seem to work, but again it paints the gradient behind the picture. In VB.net it painted it on top of the picture without any extra code.. </p>
  
  <p>Do i need to add anything extra? </p>
  
  <p>If it matters im coding in C# 2010 express.</p>