001.
using
System;
002.
using
System.Collections;
003.
using
System.ComponentModel;
004.
using
System.Data;
005.
using
System.Drawing;
006.
using
System.Drawing.Imaging;
007.
using
System.Web;
008.
using
System.Web.SessionState;
009.
using
System.Web.UI;
010.
using
System.Web.UI.WebControls;
011.
using
System.Web.UI.HtmlControls;
012.
013.
namespace
Barcodes
014.
{
015.
016.
/// <summary />
017.
/// Summary description for BarCode.
018.
/// </summary />
019.
020.
public
class
BarCode : System.Web.UI.Page
021.
{
022.
private
void
Page_Load(
object
sender, System.EventArgs e)
023.
{
024.
025.
string
Code = Request[
"code"
].ToString();
026.
027.
028.
int
w = Code.Length * 40;
029.
030.
031.
Bitmap oBitmap =
new
Bitmap(w,100);
032.
033.
034.
Graphics oGraphics = Graphics.FromImage(oBitmap);
035.
036.
037.
038.
Font oFont =
new
Font(
"IDAutomationHC39M"
, 18);
039.
040.
041.
PointF oPoint =
new
PointF(2f, 2f);
042.
SolidBrush oBrushWrite =
new
SolidBrush(Color.Black);
043.
SolidBrush oBrush =
new
SolidBrush(Color.White);
044.
045.
046.
047.
oGraphics.FillRectangle(oBrush, 0, 0, w, 100);
048.
049.
050.
051.
oGraphics.DrawString(
"*"
+ Code +
"*"
, oFont, oBrushWrite, oPoint);
052.
053.
054.
Response.ContentType =
"image/jpeg"
;
055.
oBitmap.Save (Response.OutputStream, ImageFormat.Jpeg);
056.
}
057.
}
058.
}
059.
060.
'===============================================================
061.
062.
As you can see, there
is
a barcode with the value of 1234.
063.
064.
Now, let’s create a page that has an asp:Image on it:
065.
'==============================================================
066.
<%@ Page language=
"c#"
Codebehind=
"WebForm1.aspx.cs"
067.
AutoEventWireup=
"false"
Inherits=
"BarCodes.WebForm1"
%>
068.
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
>
069.
<HTML>
070.
<HEAD>
071.
<title>WebForm1</title>
072.
<meta name=
"GENERATOR"
Content=
"Microsoft Visual Studio .NET 7.1"
>
073.
<meta name=
"CODE_LANGUAGE"
Content=
"C#"
>
074.
<meta name=
"vs_defaultClientScript"
content=
"JavaScript"
>
075.
<meta name=
"vs_targetSchema"
077.
</HEAD>
078.
<body MS_POSITIONING=
"GridLayout"
>
079.
<form id=
"Form1"
method=
"post"
runat=
"server"
>
080.
<asp:Image id=
"myBarCode"
runat=
"server"
></asp:Image>
081.
</form>
082.
</body>
083.
'===========================================================
084.
using
System;
085.
using
System.Collections;
086.
using
System.ComponentModel;
087.
using
System.Data;
088.
using
System.Drawing;
089.
using
System.Web;
090.
using
System.Web.SessionState;
091.
using
System.Web.UI;
092.
using
System.Web.UI.WebControls;
093.
using
System.Web.UI.HtmlControls;
094.
095.
namespace
BarCodes
096.
{
097.
/// <summary />
098.
/// Summary description for WebForm1.
099.
/// </summary />
100.
public
class
WebForm1 : System.Web.UI.Page
101.
{
102.
protected
System.Web.UI.WebControls.Image myBarCode;
103.
104.
private
void
Page_Load(
object
sender, System.EventArgs e)
105.
{
106.
107.
myBarCode.ImageUrl =
"BarCode.aspx?code=31231"
;
108.
}
109.
110.
#region Web Form Designer generated code
111.
override
protected
void
OnInit(EventArgs e)
112.
{
113.
114.
115.
116.
InitializeComponent();
117.
base
.OnInit(e);
118.
}
119.
120.
/// <summary />
121.
/// Required method for Designer support - do not modify
122.
/// the contents of this method with the code editor.
123.
/// </summary />
124.
private
void
InitializeComponent()
125.
{
126.
this
.Load +=
new
System.EventHandler(
this
.Page_Load);
127.
128.
}
129.
#endregion
130.
}
131.
}