首页 > 编程 > .NET > 正文

ASP.net(c#)生成条形码 code39条码生成方法

2024-07-10 12:41:13
字体:
来源:转载
供稿:网友
这几天一直在弄128条码的事情,找了相关的资料,也没找到。后来没办法只能改成code39的条码。现在把它写出来,与大家分享

1.先下载一种免费的 code39条码字体
2.建个类 为 code39 并写入以下代码
代码如下:
public sealed class Code39
{
#region private variables
/// <summary>
/// The Space Between each of Title, BarCode, BarCodeString
/// </summary>
private const int SPACE_HEIGHT = 3;
SizeF _sizeLabel = SizeF.Empty;
SizeF _sizeBarCodeValue = SizeF.Empty;
SizeF _sizeBarCodeString = SizeF.Empty;
#endregion
#region Label
private string _label = null;
private Font _labelFont = null;
/// <summary>
/// BarCode Title (条码标签)
/// </summary>
public string Label
{
set { _label = value; }
}
/// <summary>
/// BarCode Title Font (条码标签使用的字体)
/// </summary>
public Font LabelFont
{
get
{
if (_labelFont == null)
return new Font("Arial", 10);
return _labelFont;
}
set { _labelFont = value; }
}
#endregion
private string _additionalInfo = null;
private Font _addtionalInfoFont = null;
/// <summary>
/// Additional Info Font (附加信息字体)
/// </summary>
public Font AdditionalInfoFont
{
set { _addtionalInfoFont = value; }
get
{
if (_addtionalInfoFont == null) return new Font("Arial", 10);
return _addtionalInfoFont;
}
}
/// <summary>
/// Additional Info Content, if "ShowBarCodeValue" is true, the info is unvisible
/// 附加信息,如果设置ShowBarCodeValue为true,则此项不显示
/// </summary>
public string AdditionalInfo
{
set { _additionalInfo = value; }
}
#region BarCode Value and Font
private string _barCodeValue = null;
/// <summary>
/// BarCode Value (条码值)
/// </summary>
public string BarCodeValue
{
get
{
if (string.IsNullOrEmpty(_barCodeValue))
throw new NullReferenceException("The BarCodeValue has not been set yet!");
return _barCodeValue;
}
set { _barCodeValue = value.StartsWith("*") && value.EndsWith("*") ? value : "*" + value + "*"; }
}
private bool _showBarCodeValue = false;
/// <summary>
/// whether to show the original string of barcode value bellow the barcode
/// 是否在条码下方显示条码值,默认为false
/// </summary>
public bool ShowBarCodeValue
{
set { _showBarCodeValue = value; }
}
private Font _barCodeValueFont = null;
/// <summary>
/// the font of the codestring to show
/// 条码下方显示的条码值的字体
/// </summary>
public Font BarCodeValueFont
{
get
{
if (_barCodeValueFont == null)
return new Font("Arial", 10);
return _barCodeValueFont;
}
set { _barCodeValueFont = value; }
}
private int _barCodeFontSize = 50;
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表