Fill a series of rectangles using PathGradientBrush
FillRectanglesWithPathGradientBrush.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Text" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Bitmap bmp = new Bitmap(600,250);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.Lavender);
GraphicsPath gPath = new GraphicsPath();
Rectangle rect = new Rectangle(0, 0, 600, 250);
gPath.AddRectangle(rect);
PathGradientBrush pathGradientBrush = new PathGradientBrush(gPath);
pathGradientBrush.CenterColor = Color.DeepPink;
Color[] colors = { Color.FromArgb(255, 255, 225, 225) };
pathGradientBrush.SurroundColors = colors;
Rectangle rect1 = new Rectangle(25, 15, 100, 75);
Rectangle rect2 = new Rectangle(25, 100, 170, 50);
Rectangle rect3 = new Rectangle(225, 25, 35, 200);
Rectangle rect4 = new Rectangle(300, 50, 250, 150);
Rectangle[] rectangleArray = { rect1, rect2, rect3, rect4 };
g.FillRectangles(pathGradientBrush, rectangleArray);
String path = Server.MapPath("~/Image/FillRectanglesWithPathGradientBrush.jpg");
bmp.Save(path,ImageFormat.Jpeg);
Image1.ImageUrl = "~/Image/FillRectanglesWithPathGradientBrush.jpg";
g.Dispose();
bmp.Dispose();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# PathGradientBrush - how to fill a series of rectangles</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
How to fill a series of rectangles using path gradient brush
<br />System.Drawing.Drawing2D.PathGradientBrush
<br />.NET GDI+ Graphics
</h2>
<hr width="600" align="left" color="DarkBlue" />
<asp:Image
ID="Image1"
runat="server"
/>
<br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Fill A Series Of Rectangles With PathGradientBrush"
Height="45"
Font-Bold="true"
ForeColor="DarkBlue"
/>
</div>
</form>
</body>
</html>

- LinearGradientBrush LinearGradientMode Vertical
- How to draw a gradient text
- How to fill a polygon
- How to draw a line
- How to draw a polygon
- How to fill a transparent rectangle
- How to use PathGradientBrush Blend
- PathGradientBrush FocusScales property
- PathGradientBrush SurroundColors property
- PathGradientBrush WrapMode property