USING IRONBARCODE Barcode Generator .NET Tutorial Jordi Bardia 已更新:九月 1, 2025 Download IronBarcode NuGet 下载 DLL 下载 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article Given the swift rise in barcode usage, developers must be able to generate barcodes in their preferred programming language. So, this tutorial will demonstrate how to generate barcodes in .NET. Barcode Generator .NET Tutorial Creating a project in Visual Studio Installing the C# Barcode Generator Library Designing the UI for the Windows Forms Application Writing the code for core functionality Running the .NET barcode generator Let's begin the tutorial. Create the Project This tutorial uses the latest version of Visual Studio and the Windows Forms Application template. You can use the application of your choice and use your existing project and version. Open Visual Studio > Click on Create New Project > Select Windows Forms Application Template > Press Next > Name the Project > Press Next => Select your target .NET Framework => Click on Create Button. Create a new Windows Forms Application Installing the Barcode Library There are many benefits to installing a barcode generator library. IronBarcode, written in C#, provides functions to create barcodes and QR codes with just a single line of code. It also supports saving the QR code or barcode in the desired file format. Furthermore, it provides free service and runtime support for generating barcodes in .NET. Let's start with installing the IronBarcode NuGet Package. You can install it using one of the following three methods: Package Manager Console Write the following command in the Package Manager Console. It will download and install the package for you. Install-Package BarCode Package Manager Console installation step NuGet Package Manager Solution You can also install the Barcode Package by using the NuGet Package Solution. Simply follow these steps: Click on Tools > NuGet Package Manager > Manage NuGet Packages for Solution. This will open NuGet Package Manager for you. Click on Browse and search "IronBarCode", then install the library. NuGet Package Manager UI Download from the Link As an alternative, the IronBarCode.Dll can be downloaded and added to your project as a reference from .NET Barcode DLL. Design the Windows Forms The UI for the .NET Barcode generator should have 2 labels, 1 rich text box, and 1 picture box to display the generated barcode image. The image below shows a simple design for demonstration purposes. Design the Windows Forms Application Write Code for Generating Barcode Double-click the "Generate" button. The following code will appear: 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 Add the following namespaces at the top of your code file: 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 Write the following code inside the button1_Click() function: // 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 Let's understand the code, line by line: GeneratedBarcode is a data type that represents the generated barcode. CreateBarcode is the function from the BarcodeWriter class in the IronBarCode package, used to generate the barcode based on user input. BarcodeValue.Text retrieves the text entered by the user, which will be encoded into the barcode. BarcodeWriterEncoding.Code128 specifies the encoding scheme for generating the barcode. You can change this to other encoding types like BarcodeWriterEncoding.QRCode for generating QR codes. SaveAsPng("MyBarCode.png") saves the barcode image as a PNG file. BarcodeImage is a PictureBox control on the form used to display the barcode image to the user. Run the .NET Barcode Generator Press Ctrl + F5 to run the application. Run the Barcode generator application Write the value inside the text box that you want to encode in the barcode as shown below. Paste the URL to generate a barcode Now, click the "Generate" button. The barcode will be generated as shown below. Generated barcode in the Windows Forms Application Display the Value of the Barcode Next, you can display the value of the barcode with a single line of code: // 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 Output Generate a barcode from a string value Summary IronBarcode features a friendly API for developers to read and write barcodes for .NET, optimizing accuracy and ensuring a low error rate in real-world software. Visit the official documentation page for more information about IronBarcode. Currently, if you buy the complete Iron Suite, you can get five libraries for the price of two. For more information. 常见问题解答 如何在 .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 在佛罗里达州迈阿密长大,并在佛罗里达大学学习计算机科学和统计学。 相关文章 已发布十月 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. 阅读更多 已发布九月 29, 2025 IronBarcode vs. Open-Source Barcode Readers in .NET Learn how to read barcodes in C# using IronBarcode 阅读更多 已发布九月 29, 2025 How to Scan Barcodes in an ASP.NET Application Learn how to Scan Barcodes in ASP.NET using IronBarcode 阅读更多 How to Print Barcode in ASP.NET in C#How to Use Barcode Scanners in C# W...
已发布十月 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. 阅读更多
已发布九月 29, 2025 IronBarcode vs. Open-Source Barcode Readers in .NET Learn how to read barcodes in C# using IronBarcode 阅读更多
已发布九月 29, 2025 How to Scan Barcodes in an ASP.NET Application Learn how to Scan Barcodes in ASP.NET using IronBarcode 阅读更多