Initialize a new instance of the Pen class with the specified Brush
PenConstructorBrush.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(500,250);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.SandyBrown);
Pen pinkPen = new Pen(Brushes.SaddleBrown);
//this line initializes a new instance of the Pen class with the specified Brush
g.DrawRectangle(pinkPen,50,50,200,100);
String path = Server.MapPath("~/Image/PenWithSpecifiedBrush.jpg");
bmp.Save(path,ImageFormat.Jpeg);
Image1.ImageUrl = "~/Image/PenWithSpecifiedBrush.jpg";
g.Dispose();
bmp.Dispose();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>how to initialize a new instance of the Pen class with the specified Brush in asp.net drawing</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DodgerBlue; font-style:italic;">
How to initialize a new instance of the Pen class
<br /> with the specified Brush in asp.net drawing
<br />Pen Constructor (Brush)
</h2>
<hr width="500" align="left" color="DeepSkyBlue" />
<asp:Image
ID="Image1"
runat="server"
/>
<br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="PenWithSpecifiedBrush"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>

- Initialize a new instance of the Pen class with color
- How to use Pen CompoundArray property
- How to use Pen EndCap property
- Pen DashStyle Dot
- How to use Pen DashStyle property
- How to create Pen custom dash pattern
- How to use Pen DashOffset
- How to change Pen width
- How to use a Pen to draw lines
- How to use a Pen to draw rectangles