Preferred Language:
Listing 29.34 - GradientPanel.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;
using System.ComponentModel;
using System.Drawing;
namespace myControls
{
[Designer(typeof(GradientPanelDesigner))]
[ParseChildren(false)]
public class GradientPanel : WebControl
{
private GradientDirection _direction = GradientDirection.Horizontal;
private Color _startColor = Color.DarkBlue;
private Color _endColor = Color.White;
public GradientDirection Direction
{
get { return _direction; }
set { _direction = value; }
}
public Color StartColor
{
get { return _startColor; }
set { _startColor = value; }
}
public Color EndColor
{
get { return _endColor; }
set { _endColor = value; }
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
writer.AddStyleAttribute(HtmlTextWriterStyle.Filter, this.GetFilterString());
base.AddAttributesToRender(writer);
}
public string GetFilterString()
{
return String.Format("progid:DXImageTransform.Microsoft.Gradient(gradientType={0},startColorStr={1},endColorStr={2})", _direction.ToString("d"), ColorTranslator.ToHtml(_startColor), ColorTranslator.ToHtml(_endColor));
}
public GradientPanel()
{
this.Width = Unit.Parse("500px");
}
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Div;
}
}
}
public enum GradientDirection
{
Vertical = 0,
Horizontal = 1
}
public class GradientPanelDesigner : ContainerControlDesigner
{
protected override void AddDesignTimeCssAttributes(System.Collections.IDictionary styleAttributes)
{
GradientPanel gPanel = (GradientPanel)this.Component;
styleAttributes.Add("filter", gPanel.GetFilterString());
base.AddDesignTimeCssAttributes(styleAttributes);
}
}
}
Need ASP.NET and Visual Studio 2008 Training?
- Learn ASP.NET 3.5 from Stephen Walther, author of ASP.NET 3.5 Unleashed.
We've provided ASP.NET training for NASA, Lockheed Martin, the National Science Foundation, Verizon,
Boeing, the US House of Representatives, Kaiser, Petco, Mary Kay, and Microsoft.
Why not your company?
-
Receive a four day, hands-on, intensive workshop.
-
We fly to you, anywhere in the world.
-
We can bring our own laptops.
To learn more, visit the
Superexpert Training website.