彩票走势图

Barcode Professional SDK for .NET使用教程(五):在Web应用程序中使用Barcode Professional

原创|使用教程|编辑:龚雪|2016-03-21 15:05:14.000|阅读 455 次

概述:本次教程将向您介绍如何在ASP.NET Web应用程序中轻松使用Barcode Professional SDK for .NET。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

在教程开始前您需要完成以下几项工作:

  • 使用Visual Studio 2008 或者 VWD 2008 Express Edition 创建一个ASP.NET网页
  • 创建一个简单的ASP.NET WebForm (ASPX)来动态地生成条形码
  • 通过Barcode Professional SDK for .NET为条形码生成创建一个ASP.NET HTTP Handler (ASHX)

最新版Barcode Professional SDK for .NET下载

操作步骤:

  • 确定您已经安装了Barcode Professional SDK for .NET
  • 启动Visual Studio 2008或者VWD 2008并创建一个ASP.NET网页
  • 添加一个到Barcode Professional SDK for .NET集合的调用
  • 打开Default.ASPX文件并在源代码视窗中粘贴以下内容 :
<html xmlns="//www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Barcode Professional SDK in ASP.NET</title>
    <style type="text/css">
        .newStyle1 {
            font-family: arial, Helvetica, sans-serif;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div class="newStyle1">
            <h3>Barcode Professional SDK in ASP.NET</h3>
            <br />
            Enter Value to Encode:
            <br />
            <asp:TextBox ID="TextBox1" runat="server" Width="264px">
            </asp:TextBox><asp:Button ID="Button1" runat="server" Text="Barcode Now!" 
                onclick="Button1_Click" />
            <br />
            <br />
            <asp:Image ID="Image1" runat="server" Visible="false" />
        </div>    
    </form>
</body>
</html>      
  • 在设计视窗中双击“Barcode Now!"按钮并复制以下代码到按钮的Click事件处理器中:

VB

If (Me.TextBox1.Text.Length > 0) Then
    Me.Image1.ImageUrl = "~/BarcodeGen.ashx?code=" + Me.TextBox1.Text
    Me.Image1.Visible = True
End If	    	

C#

if (this.TextBox1.Text.Length >  0)
{
    this.Image1.ImageUrl = "~/BarcodeGen.ashx?code=" + this.TextBox1.Text;
    this.Image1.Visible = true;
}			    
  • 新添加一个"Generic Handler"类型的项并命名为BarcodeGen.ASHX. 在这个ASP.NET处理程序中,我们将为条形码生成创建一个BarcodeProfessional类的实例。在文件创建后,打开并粘贴以下代码:

VB

<%@ WebHandler Language="VB" Class="BarcodeGen" %>

Imports System
Imports System.Web

Imports Neodynamic.SDK

Public Class BarcodeGen : Implements IHttpHandler
    
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        
        'Get value to encode from querystring
        Dim valueToEncode As String = context.Request("code")
                
        'Create BarcodeProfessional object        
        Dim bc As New BarcodeProfessional()
        'Set barcode standard
        bc.Symbology = Symbology.Code128
        'Set value to encode
        bc.Code = valueToEncode

        'Generate barcode        
        context.Response.ContentType = "image/gif"
        context.Response.BinaryWrite(bc.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Gif))
    End Sub
 
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class    	

C#

<%@ WebHandler Language="C#" Class="BarcodeGen" %>

using System;
using System.Web;

using Neodynamic.SDK;

public class BarcodeGen : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {

        //Get value to encode from querystring
        string valueToEncode = context.Request["code"];
        
        //Create BarcodeProfessional object        
        BarcodeProfessional bc = new BarcodeProfessional();
        //Set barcode standard
        bc.Symbology = Symbology.Code128;
        //Set value to encode
        bc.Code = valueToEncode;

        //Generate barcode        
        context.Response.ContentType = "image/gif";
        context.Response.BinaryWrite(bc.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Gif));
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}			    
  • 最后,用VS运行您的项目。您会得到以下内容:
IE
Firefox

标签:条码生成

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@capbkgr.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP