USING IRONBARCODE Barcode Generator .NET Tutorial Jordi Bardia 已更新:九月 1, 2025 下载 IronBarcode NuGet 下载 DLL 下载 免费试用 法学硕士副本 法学硕士副本 将页面复制为 Markdown 格式,用于 LLMs 在 ChatGPT 中打开 向 ChatGPT 咨询此页面 在双子座打开 向 Gemini 询问此页面 在双子座打开 向 Gemini 询问此页面 打开困惑 向 Perplexity 询问有关此页面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 复制链接 电子邮件文章 鉴于条形码使用量的迅速增长,开发人员必须能够使用他们喜欢的编程语言生成条形码。 因此,本教程将演示如何在 .NET 中生成条形码。 条形码生成器 .NET 教程 在 Visual Studio 中创建项目 安装 C# 条形码生成器库 设计 Windows 窗体应用程序的用户界面 编写核心功能的代码 运行 .NET 条形码生成器 让我们开始教程。 创建项目 本教程使用最新版本的 Visual Studio 和 Windows 窗体应用程序模板。 您可以选择使用您喜欢的应用程序,并使用您现有的项目和版本。 打开 Visual Studio > 单击"创建新项目" > 选择"Windows 窗体应用程序模板" > 按"下一步" > 为项目命名 > 按"下一步" => 选择目标 .NET Framework => 单击"创建"按钮。 条形码生成器 .NET 教程,图 1:创建一个新的 Windows 窗体应用程序 创建一个新的 Windows 窗体应用程序 安装条形码库 安装条形码生成器库有很多好处。 IronBarcode 是用 C# 编写的,它提供了只需一行代码即可创建条形码和二维码的功能。 它还支持以所需的文件格式保存二维码或条形码。 此外,它还为在 .NET 中生成条形码提供免费服务和运行时支持。 我们先来安装 IronBarcode NuGet 包。 您可以使用以下三种方法之一进行安装: 包管理器控制台 在包管理器控制台中写下以下命令。 它将为您下载并安装程序包。 Install-Package BarCode 条形码生成器 .NET 教程,图 2:包管理器控制台安装步骤 程序包管理器控制台安装步骤 NuGet 包管理器解决方案 您还可以使用 NuGet 包解决方案安装条形码包。 只需按照这些步骤操作: 点击工具 > NuGet程序包管理器 > 管理解决方案的NuGet程序包。 这将为您打开NuGet包管理器。 点击"浏览"并搜索"IronBarCode",然后安装该库。 条形码生成器 .NET 教程,图 3:NuGet 包管理器用户界面 NuGet包管理器UI 从链接下载 作为替代方案,您可以从 .NET 条形码 DLL 下载IronBarcode.Dll并将其作为引用添加到您的项目中。 设计 Windows 窗体 .NET 条形码生成器的用户界面应包含 2 个标签、1 个富文本框和 1 个图片框,用于显示生成的条形码图像。 下图展示了一个简单的设计示例。 条形码生成器 .NET 教程,图 4:设计 Windows 窗体应用程序 设计 Windows 窗体应用程序 编写生成条形码的代码 双击"生成"按钮。 将显示以下代码: private void button1_Click(object sender, EventArgs e) { // This function will be triggered when the "Generate" button is clicked } private void button1_Click(object sender, EventArgs e) { // This function will be triggered when the "Generate" button is clicked } Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) ' This function will be triggered when the "Generate" button is clicked End Sub $vbLabelText $csharpLabel 在代码文件顶部添加以下命名空间: using IronBarCode; // Import the IronBarCode library to handle barcode operations using System.Drawing; // Import for image manipulation using System.Windows.Forms; // Import for Windows Forms functionality using IronBarCode; // Import the IronBarCode library to handle barcode operations using System.Drawing; // Import for image manipulation using System.Windows.Forms; // Import for Windows Forms functionality Imports IronBarCode ' Import the IronBarCode library to handle barcode operations Imports System.Drawing ' Import for image manipulation Imports System.Windows.Forms ' Import for Windows Forms functionality $vbLabelText $csharpLabel 在button1_Click()函数中写入以下代码: // Generate a barcode with the specified value and encoding GeneratedBarcode MyBarCode = IronBarCode.BarcodeWriter.CreateBarcode(BarcodeValue.Text, BarcodeWriterEncoding.Code128); // Save the generated barcode as a PNG file MyBarCode.SaveAsPng("MyBarCode.png"); // Display the generated barcode image in the PictureBox BarcodeImage.Image = new Bitmap("MyBarCode.png"); // Generate a barcode with the specified value and encoding GeneratedBarcode MyBarCode = IronBarCode.BarcodeWriter.CreateBarcode(BarcodeValue.Text, BarcodeWriterEncoding.Code128); // Save the generated barcode as a PNG file MyBarCode.SaveAsPng("MyBarCode.png"); // Display the generated barcode image in the PictureBox BarcodeImage.Image = new Bitmap("MyBarCode.png"); ' Generate a barcode with the specified value and encoding Dim MyBarCode As GeneratedBarcode = IronBarCode.BarcodeWriter.CreateBarcode(BarcodeValue.Text, BarcodeWriterEncoding.Code128) ' Save the generated barcode as a PNG file MyBarCode.SaveAsPng("MyBarCode.png") ' Display the generated barcode image in the PictureBox BarcodeImage.Image = New Bitmap("MyBarCode.png") $vbLabelText $csharpLabel 让我们逐行理解代码: GeneratedBarcode是一种表示生成的条形码的数据类型。 CreateBarcode是IronBarCode包中的BarcodeWriter类中的函数,用于根据用户输入生成条形码。 BarcodeValue.Text获取用户输入的文本,该文本将被编码到条形码中。 BarcodeWriterEncoding.Code128指定生成条形码的编码方案。 您可以将其更改为其他编码类型,例如BarcodeWriterEncoding.QRCode ,用于生成二维码。 SaveAsPng("MyBarCode.png")将条形码图像保存为 PNG 文件。 BarcodeImage是窗体上的 PictureBox 控件,用于向用户显示条形码图像。 运行 .NET 条形码生成器 按Ctrl + F5运行应用程序。 条形码生成器 .NET 教程,图 5:运行条形码生成器应用程序 运行条形码生成器应用程序 请在文本框中输入您想要编码到条形码中的值,如下所示。 条形码生成器 .NET 教程,图 6:粘贴 URL 以生成条形码 粘贴网址以生成条形码 现在,点击"生成"按钮。 条形码将按如下所示生成。 条形码生成器 .NET 教程,图 7:在 Windows 窗体应用程序中生成的条形码 在 Windows 窗体应用程序中生成的条形码 显示条形码的值 接下来,您可以使用一行代码显示条形码的值: // Add the encoded barcode value as text below the barcode image MyBarCode.AddBarcodeValueTextBelowBarcode(); // Add the encoded barcode value as text below the barcode image MyBarCode.AddBarcodeValueTextBelowBarcode(); ' Add the encoded barcode value as text below the barcode image MyBarCode.AddBarcodeValueTextBelowBarcode() $vbLabelText $csharpLabel 输出 条形码生成器 .NET 教程,图 8:从字符串值生成条形码 根据字符串值生成条形码 摘要 IronBarcode 为开发人员提供了一个友好的 API,用于读取和写入 .NET 条形码,从而优化准确性并确保实际软件中的低错误率。 请访问官方文档页面,了解有关 IronBarcode 的更多信息。 目前,如果您购买 完整的 Iron Suite,可以以两本的价格获得五个库。 了解更多信息。 常见问题解答 如何在 .NET 中生成条形码? 您可以使用 IronBarcode 库在 .NET 中生成条形码,通过在 Visual Studio 中创建项目、安装库、设计 UI 和编写代码来生成和显示条形码。 条形码库的安装方法有哪些? 您可以使用包管理器控制台、NuGet 包管理器解决方案来安装 IronBarcode 库,或者直接下载 DLL 并将其添加到项目中。 条形码生成器应用程序的必备 UI 元素是什么? 条形码生成器应用程序的必备 UI 元素包括两个标签、一个用于输入的富文本框和一个用于显示生成的条形码图像的图片框。 编码条形码生成函数涉及哪些步骤? 要编码条形码生成函数,需要在 button1_Click 函数中编写代码,使用 IronBarcode 生成条形码,将其保存为 PNG,并显示在 PictureBox 中。 使用该库可以生成哪些类型的条形码? IronBarcode 支持生成多种条形码类型,包括 Code128 和 QRCode 等。 如何在生成的条形码下方添加文本? 您可以使用 IronBarcode 库中的 AddBarcodeValueTextBelowBarcode 方法,将条形码的编码值作为文本添加到图像下方。 使用 IronBarcode 库有什么优势? 使用 IronBarcode 提供了优化的条形码生成,具有高性能和准确性、用户友好的 API 以及在实际应用中的低错误率。 在哪里可以访问条形码库的详细文档? 可以在官方 IronBarcode 网站上找到 IronBarcode 库的详细文档和示例。 条形码库目前有没有促销活动? 是的,目前的促销活动是购买完整 Iron Suite 可以享受五个库的价格相当于两个库的价格。 如何排除 .NET 中条形码生成的常见问题? 常见问题通常可以通过确保 IronBarcode 库正确安装、检查确保 UI 组件正确配置以及验证条形码生成代码无误来解决。 Jordi Bardia 立即与工程团队聊天 软件工程师 Jordi 最擅长 Python、C# 和 C++,当他不在 Iron Software 利用这些技能时,他就在游戏编程。分享产品测试、产品开发和研究的责任,Jordi 在持续的产品改进中增加了巨大的价值。多样的经验使他面临挑战并保持投入,他表示这是在 Iron Software 工作的最喜欢的方面之一。Jordi 在佛罗里达州迈阿密长大,并在佛罗里达大学学习计算机科学和统计学。 相关文章 已发布十二月 18, 2025 IronBarcode 与 Open Source Barcode Reader .NET 的比较 Learn how to read barcodes in C# using IronBarcode 阅读更多 已发布十二月 18, 2025 C# 中的数据矩阵生成器:IronBarcode 完整指南 数据矩阵生成器C#教程。了解如何使用IronBarcode创建ECC200数据矩阵条形码。简单的2D条码生成代码示例。 阅读更多 已发布十月 19, 2025 How to Print Barcodes in Crystal Reports with VB.NET Generate and print barcodes in Crystal Reports using VB.NET. Step-by-step tutorial with IronBarcode SDK for reliable barcode integration. 阅读更多 How to Print Barcode in ASP.NET in C#How to Use Barcode Scanners in C# W...
已发布十二月 18, 2025 IronBarcode 与 Open Source Barcode Reader .NET 的比较 Learn how to read barcodes in C# using IronBarcode 阅读更多
已发布十二月 18, 2025 C# 中的数据矩阵生成器:IronBarcode 完整指南 数据矩阵生成器C#教程。了解如何使用IronBarcode创建ECC200数据矩阵条形码。简单的2D条码生成代码示例。 阅读更多
已发布十月 19, 2025 How to Print Barcodes in Crystal Reports with VB.NET Generate and print barcodes in Crystal Reports using VB.NET. Step-by-step tutorial with IronBarcode SDK for reliable barcode integration. 阅读更多