重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.net制作条形码 条形码程序编程c语言

VB.NET如何操作条码扫描枪,如何设置,如何进行条形码的设置及打印

这个要看扫描枪的通讯接口和通讯协议,以及接口程序是否支持VB.NET等。

网站建设哪家好,找成都创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了赫山免费建站欢迎大家使用!

vb.net条码打印控件

工具箱,然后随便选择一项,右键 选择项,在.com控件里,microsoft bar ctrol 9.0

如何在vb.net 中录入条形码字符,谢谢

93条码和CODE39一样,起始符和结束符都是*号,你做的条码扫描不出来的原因,估计和校验码有关。93条码规定在数据的最后有两个校验位C和K,如果你的数据里没有生成这两个校验位,那肯定是无法扫描的。

如何使用Aspose.BarCode创建条形码

在本文中,我们将使用ASP.NET web services创建条形码。我们还将创建含有条形码的Windows Forms和Console应用程序。该过程会用到Aspose.BarCode这个控件。

这样做有什么好处呢?

Web services的主要优势在于软件与外部应用程序集成。标准化的请求/响应模型,任何基于XML web service的客户端应用程序都可以从中受益。以下是简短的条形码服务的表现形式。客户端不需要在此安装Aspose.BarCode for .NET。他们只需发送两个字符串值(代码电文和符号),就将从服务端获取条形码(字节数组)。

打开Microsoft Visual Studio,并创建一个“ASP.NET Web Service Application”新项目,命名为“BarCodeService”。 添加以下引用。

1.“Add Reference”对话框的System.Drawing from .NET选项卡

2. Aspose.BarCode。

找到 Aspose.BarCode for .NET安装的位置并选择。Visual Studio会添加了一个默认的类“Service1“到Service1.asmx文档的Web Service项目。 打开它,并为这个类添加以下方法。

[C#]

[WebMethod]

public byte[] GetBarcode(string strCodetext, string strSymbology)

{

// Initialize BarCodeBuilder

BarCodeBuilder builder = new BarCodeBuilder();

// Set codetext

builder.CodeText = strCodetext;

// Set barcode symbology

builder.SymbologyType = (Symbology) Enum.Parse(typeof(Symbology), strSymbology, true);

// Create and save the barcode image to memory stream

MemoryStream imgStream = new MemoryStream();

builder.Save(imgStream, ImageFormat.Png);

// Return the barcode image as a byte array

return imgStream.ToArray();

}

[VB.NET]

_

Public Function GetBarcode(ByVal strCodetext As String, ByVal strSymbology As String) As Byte()

' Initialize BarCodeBuilder

Dim builder As BarCodeBuilder = New BarCodeBuilder()

' Set codetext

builder.CodeText = strCodetext

' Set barcode symbology

builder.SymbologyType = CType(System.Enum.Parse(GetType(Symbology), strSymbology, True), Symbology)

' Create and save the barcode image to memory stream

Dim imgStream As MemoryStream = New MemoryStream()

builder.Save(imgStream, ImageFormat.Png)

' Return the barcode image as a byte array

Return imgStream.ToArray()

End Function

web方法需要客户端以下两个参数:

1.Codetext

2.Symbology

这些参数为String字符串类型。这些参数被传递到BarCodeBuilder类,然后创建条形码,并以字节数组的形式给客户端发送条形码。

使用Windows Forms应用中的Web Service

打开Visual Studio,并创建一个新类型“Windows Application”的项目。命名项目为“GetBarCodeWinForms”。通过右键单击“References”,选择,然后从菜单中选择““Add Service Reference”为web service添加引用。键入web service的地址。在得到正确的结果之后,在Namespace命名域中输入“BarCodeService”,点击“Ok”按钮以添加引用。

设计形式如下图所示:

它包含以下控件:

1.Textbox:输入代码

2.Combobox:输入符号类型

3.Button:调用web service

4.Picturebox:显示条形码

为代码的按钮单击事件添加以下代码。

[C#]

// Initialize the Barcode Web Service

BarCodeService.Service1SoapClient barcodeService = new BarCodeService.Service1SoapClient();

// Call the GetBarcode web method

// Pass codetext and symbology in parameters

// Get the barcode image returned from the web method in the form of byte array

byte[] arrBarcodeImage = barcodeService.GetBarcode(txtCodetext.Text, cmbSymbology.Text);

// Create an instance of Image from the byte array

MemoryStream imgStream = new MemoryStream(arrBarcodeImage);

Image imgBarcode = Bitmap.FromStream(imgStream);

// Assign the barcode image to the Picturebox control

picBarcodeImage.Image = imgBarcode;

picBarcodeImage.Height = imgBarcode.Height;

picBarcodeImage.Width = imgBarcode.Width;

[VB.NET]

' Initialize the Barcode Web Service

Dim barcodeService As BarCodeService.Service1SoapClient = New BarCodeService.Service1SoapClient()

' Call the GetBarcode web method

' Pass codetext and symbology in parameters

' Get the barcode image returned from the web method in the form of byte array

Dim arrBarcodeImage As Byte() = barcodeService.GetBarcode(txtCodetext.Text, cmbSymbology.Text)

' Create an instance of Image from the byte array

Dim imgStream As MemoryStream = New MemoryStream(arrBarcodeImage)

Dim imgBarcode As Image = Bitmap.FromStream(imgStream)

' Assign the barcode image to the Picturebox control

picBarcodeImage.Image = imgBarcode

picBarcodeImage.Height = imgBarcode.Height

picBarcodeImage.Width = imgBarcode.Width

运行该应用程序,指定某些值,点击“Get Barcode”按钮。应用程序将使用条形码web service,并从中获取条形码。条形码将显示在如下窗体中。

从Console Application控制台应用程序使用Web Service

在Visual Studio中创建一个“Console Application”新项目,将项目命名为“GetBarCodeConsole”。 将该引用添加到条码服务中,方法和winforms应用程序中的相同。在main()方法中编写以下代码。

[C#]

try

{

// Initialize the Barcode Web Service

BarCodeService.Service1SoapClient c = new GetBarCodeConsole.BarCodeService.Service1SoapClient();

// Call the GetBarcode web method

// Pass codetext and symbology in parameters

// Get the barcode image returned from the web method in the form of byte array

byte[] arrBarcodeImage = c.GetBarcode("console application", "pdf417");

// Save the byte array (barcode image) to disk

FileStream imgWriter = new FileStream("barcode.png", FileMode.Create);

imgWriter.Write(arrBarcodeImage, 0, arrBarcodeImage.Length);

imgWriter.Close();

// Open the barcode image

Process.Start("barcode.png");

}

catch (Exception ex)

{

Console.WriteLine(ex.Message);

}

Console.WriteLine("Press any key to exit....");

Console.ReadKey();

[VB.NET]

Try

' Initialize the Barcode Web Service

Dim c As BarCodeService.Service1SoapClient = New GetBarCodeConsole.BarCodeService.Service1SoapClient()

' Call the GetBarcode web method

' Pass codetext and symbology in parameters

' Get the barcode image returned from the web method in the form of byte array

Dim arrBarcodeImage As Byte() = c.GetBarcode("console application", "pdf417")

' Save the byte array (barcode image) to disk

Dim imgWriter As FileStream = New FileStream("barcode.png", FileMode.Create)

imgWriter.Write(arrBarcodeImage, 0, arrBarcodeImage.Length)

imgWriter.Close()

' Open the barcode image

Process.Start("barcode.png")

Catch ex As Exception

Console.WriteLine(ex.Message)

End Try

Console.WriteLine("Press any key to exit....")

Console.ReadKey()

运行该应用程序,它将使用条形码web service,得到条形码,并保存在本地磁盘上。

VB.net如何在水晶报表上打印条码

很简单。只需要安装Code39字体,或者加载到系统中就可以。

报表设置该字体自然就表示成条形码了。

Code39字体从网上搜索能搜索到。

VB 识别条形码

一、条形码的读取

用过键盘口式的扫条码工具的朋友就知道,它就如同在键盘上按下数字键一样,基本不需任何编程和处理。但如果你使用的是其它接口的话,可能你就要为该设备编写通讯代码了。以下有一段简单的25针串口的条码读取器通讯代码。

Option Explicit

Dim sData As String

Private Sub Form_Load()

With MSComm1

.CommPort = 3 '设为COM3,试运行的系统而定,你可提供一个Combox让用户选择。

.PortOpen = True '打开通讯端口

End With

End Sub

Private Sub MSComm1_OnComm()

Dim EndPos As Integer

Select Case MSComm1.CommEvent

Case comEvReceive '当有数据传送过来时

sData = sData Trim(MSComm1.Input)

'检索回车,通常读卡机每组数据结尾都返回一个回车作为结束符

EndPos = InStr(1, sData, Chr(13))

If EndPos = 0 Then '如果未结束就继续努力

Else '读完一组。

lblBarCode.Caption = sData '显示一组条形码

With lstBarCode

.AddItem Mid(sData, 1, EndPos - 1) '添加一组条形码到列表

End With

sData = "" '清空

End If

End Select

End Sub

Private Sub cmdEnd_Click()

MSComm1.PortOpen = False '关闭端口

End

End Sub

二:条形码的生成

在VB上编程本来就不难。以下关于条形码生成的代码也是很容易理解,只需使用一个OFFICE的附带的 BarCode控件就可以轻松打印出11种不同标准的条形码,足以满足我们的要求。想起我书架上的一本书中的一篇用Turbo C编写条形码打印程序文章,长篇大论,那时不知看了n天,打了n小时字结果也不尽人意,现在真是幸福多了:)。废话说完,得回归正题。且看条形码生成的代码及有关说明。

源代码主要由两个窗体(frmMain主窗体和frmOption条码设置窗体)和两个模块组成(modGetScreen.bas、SysDLG32.bas)。考虑到篇幅,这里只列出部分较为关键的代码。

新建一个标准工程,添加一个名为(Microsoft Access BarCode

Control9)的条形码部件,并添加一个条码控件到窗口,并将窗口改名为frmMain,如图所示。由于控件比较多,这里不便细说,详细内容请看源代码。

模块modGetScreen.bas代码如下:

Option Explicit

声明BitBlt、GetDesktopWindow、GetWindowDC、ReleaseDC这几个API函数略

Public RegUser As Boolean

Sub GetObjImage1(Obj As Object, OwnerForm As PictureBox, Picture1

As PictureBox)

'hDC

Dim hWndDesk As Long

Dim hDCDesk As Long

'区域表达变量

Dim x As Long

Dim y As Long

Dim w As Long

Dim h As Long

x = Obj.Left Screen.TwipsPerPixelX

y = Obj.Top Screen.TwipsPerPixelY

w = Obj.Width Screen.TwipsPerPixelX

h = Obj.Height Screen.TwipsPerPixelY

hDCDesk = OwnerForm.hdc

'取出图像

Call BitBlt(Picture1.hdc, 0, 0, w, h, hDCDesk, x, y,

vbSrcCopy)

Call ReleaseDC(hWndDesk, hDCDesk)

End Sub

主窗体frmMain.frm部分代码如下:

Private Sub cmdPrint_Click()

'生成条形码图像

Dim r As Long, i As Integer, t As String,cfile As

String '临时变量

t = BarCode

For i = 0 To Val(Times) - 1

BarCode1.Value = BarCode + i

DoEvents

Picture1.Refresh

GetObjImage1 BarCode1, Conel, Picture1

If RegUser = False Then '如果未注册添加MASK标记

Picture1.PaintPicture Picture2.Picture, 300, 300

End If

If Dir(SavePath, vbDirectory) = "" Then MkDir SavePath

SavePath = SavePath IIf(Right(SavePath, 1) "", "",

"")

cfile = SavePath BarCode1.Value ".bmp"

SavePicture Picture1.Image, cfile '将条形码保存为图像文件以便打印

Next

BarCode = t

End Sub

条形码设置窗体frmOption.frm代码如下:

Option Explicit

'条形码设置模块

Private Sub cboBig_Click()

BarCode1.Style = cboBig.ListIndex '改变标准

End Sub

Private Sub cboDirection_Click()

BarCode1.Direction = cboDirection.ListIndex '改变方向

End Sub

Private Sub cboLine_Click()

BarCode1.LineWeight = cboLine.ListIndex '改变线宽

End Sub

Private Sub cboSmall_Click()

BarCode1.SubStyle = cboSmall.ListIndex '改变样式

End Sub

Private Sub Check1_Click()

BarCode1.ShowData = Check1.Value '是否显示数据

End Sub

Private Sub cmdChange_Click()

'设置长、宽大小

BarWidth = BarCode1.Height

BarHeight = BarCode1.Width

cmdRefresh_Click

End Sub

Private Sub cmdOK_Click()

'传送条形码设定到主界面

With frmMain.BarCode1

.LineWeight = BarCode1.LineWeight

.Style = BarCode1.Style

.SubStyle = BarCode1.SubStyle

.Direction = BarCode1.Direction

.Width = BarCode1.Width

.Height = BarCode1.Height

.ShowData = BarCode1.ShowData

Me.Hide

End With

With frmMain

.Picture1.Width = .BarCode1.Width

.Picture1.Height = .BarCode1.Height

.Conel.Width = .BarCode1.Width

.Conel.Height = .BarCode1.Height

End With

End Sub

Private Sub cmdRefresh_Click()

BarCode1.Width = BarWidth

BarCode1.Height = BarHeight

End Sub

Private Sub Form_Load()

LoadBarInfo

BarWidth = BarCode1.Width

BarHeight = BarCode1.Height

End Sub

Sub LoadBarInfo() '初始化选项

LoadBigClass cboBig

LoadSmallClass cboSmall

LoadLineSize cboLine

LoadDirection cboDirection

End Sub

Sub LoadBigClass(cbo As ComboBox) '条码标准

With cbo

.AddItem "UPC-A"

.AddItem "UPC-E"

.AddItem "EAN-13"

.AddItem "EAN-8"

.AddItem "Case Code"

.AddItem "Codabar (NW-T)"

.AddItem "Code-39"

.AddItem "Code-128"

.AddItem "U.S. Postnet"

.AddItem "U.S. Postal FIM"

.AddItem "JP Post"

.ListIndex = 2

End With

End Sub

Sub LoadSmallClass(cbo As ComboBox) '条码样式

With cbo

.AddItem "Standard"

.AddItem "2-Digit Supplement"

.AddItem "5-Digit Supplement"

.AddItem "POS Case Code"

.ListIndex = 0

End With

End Sub

许多人在编写数据库应用程序时,都想要加上条形码功能加强工作效率,尤其是销售管理,图书馆管理这类流量大的应用软件,但由于条形码技术难以掌握、标谁又多以及过去的技术种种原因,使得许多人望而却步。本文介绍的一套简单实用的条形码解决方法,希望能帮助各位完善软件系统的功能。


本文标题:vb.net制作条形码 条形码程序编程c语言
网站链接:http://cqcxhl.cn/article/higjhs.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP