Web 2.0 Style Text in C#

Now you get to add that cheesy web 2.0 text to your C# projects.

This is the simple Web2GradientBrushes class I used to draw the gradients. There are two other gradients in there, so try them out in the code sample. If you decide to add some more please leave comments.

using System.Drawing.Drawing2D;
using System.Collections.Generic;

namespace System.Drawing.Drawing2D {
  public class Web2GradientBrushes {
    private Rectangle rectangle;
    private RectangleF rectangleF;
    private List<LinearGradientBrush> usedBrushes;

    public Web2GradientBrushes(Rectangle rectangle) {
      this.rectangle = rectangle;
    }
    public Web2GradientBrushes(RectangleF rectangleF) {
      this.rectangleF = rectangleF;
    }

    public LinearGradientBrush Black {
      get {
        return this.getBrush(Color.FromArgb(69, 68, 68), Color.Black);
      }
    }
    public LinearGradientBrush Yellow {
      get {
        return this.getBrush(Color.FromArgb(249, 234, 148), Color.FromArgb(249, 218, 45));
      }
    }
    public LinearGradientBrush Blue {
      get {
        return this.getBrush(Color.FromArgb(119, 183, 227), Color.FromArgb(50, 112, 237));
      }
    }


    public void DisposeUsedBrushes() {
      if (this.usedBrushes != null) {
        foreach (LinearGradientBrush brush in this.usedBrushes) {
          try {
            brush.Dispose();
          }
          catch { }
        }
        this.usedBrushes.Clear();
      }
    }

    private LinearGradientBrush getBrush(Color color1, Color color2) {
      LinearGradientBrush lgb = null;

      if (!this.rectangle.IsEmpty) {
        lgb = new LinearGradientBrush(this.rectangle, color1, color2, LinearGradientMode.Vertical);
      }
      else if (!this.rectangleF.IsEmpty) {
        lgb = new LinearGradientBrush(this.rectangleF, color1, color2, LinearGradientMode.Vertical);
      }

      if (lgb != null) {
        if (this.usedBrushes == null) { this.usedBrushes = new List<LinearGradientBrush>(); }
        this.usedBrushes.Add(lgb);
      }
      return lgb;
    }
  }
}

Download Code Here (C# 2008 Express Edition)