使用IRONBARCODE 條碼生成器.NET教程 Jordi Bardia 更新:9月 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 套件管理器使用者介面 從連結下載 作為替代方案,您可以從 .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 中生成 BarCode? 您可以使用 IronBarcode library 在 .NET 中生成條碼,方法是在 Visual Studio 中建立專案、安裝函式庫、設計使用者介面,以及編寫程式碼來產生和顯示條碼。 BarCode 程式庫的安裝方法為何? 您可以使用套件管理員控制台、NuGet 套件管理員解決方案來安裝 IronBarcode 函式庫,或直接下載 DLL 並將其加入您的專案。 條碼產生器應用程式必須具備哪些 UI 元素? 條碼產生器應用程式的基本 UI 元素包括兩個標籤、一個用於輸入的富文本框,以及一個用於顯示產生的條碼影像的圖片框。 編碼 BarCode 生成功能涉及哪些步驟? 要編寫條碼產生功能的程式碼,請在 button1_Click 函式中寫入程式碼,以使用 IronBarcode 產生條碼,並將其儲存為 PNG,然後顯示在 PictureBox 中。 使用這個函式庫可以產生哪些類型的 BarCode? IronBarcode 支援產生各種條碼類型,包括 Code128 和 QRCode 等等。 如何在生成的 BarCode 下方添加文字? 您可以使用 IronBarcode 程式庫中的 AddBarcodeValueTextBelowBarcode 方法,將條碼的編碼值以文字的形式加入影像下方。 使用 IronBarcode 程式庫有什麼好處? 使用 IronBarcode 可提供優化的條碼生成功能,具有高效能和高準確度、用戶友好的 API 以及在實際應用中的低錯誤率。 在哪裡可以取得 BarCode 程式庫的詳細說明文件? IronBarcode 程式庫的詳細說明文件和範例可在 IronBarcode 官方網站找到。 BarCode 程式庫目前有任何促銷活動嗎? 是的,現在有一個促銷活動,購買完整的 Iron Suite 可以讓您以兩個的價格獲得五個函式庫。 如何排除在 .NET 中生成 BarCode 的常見問題? 常見問題通常可透過確保 IronBarcode 函式庫的正確安裝、檢查 UI 元件是否配置正確,以及驗證條碼產生程式碼是否無誤來解決。 Jordi Bardia 立即與工程團隊聊天 軟體工程師 Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担产品测测试,产品开发和研究的责任时,Jordi 为持续的产品改进增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。 相關文章 發表日期 12月 18, 2025 IronBarcode 與開源條碼閱讀器 .NET 的對比 了解如何使用IronBarcode在C#中讀取條碼 閱讀更多 發表日期 12月 18, 2025 C# 資料矩陣產生器:IronBarcode 完整指南 數據矩陣生成器C#教程。學習如何使用IronBarcode創建ECC200數據矩陣條碼。簡單的2D條碼生成代碼示例。 閱讀更多 發表日期 10月 19, 2025 如何使用VB.NET在Crystal Reports中打印條碼 在VB.NET中使用IronBarcode SDK在Crystal Reports中生成和打印條碼的分步教程,確保可靠的條碼集成。 閱讀更多 如何在ASP.NET C#中打印條碼如何在C# Windows應用程式中...
發表日期 12月 18, 2025 C# 資料矩陣產生器:IronBarcode 完整指南 數據矩陣生成器C#教程。學習如何使用IronBarcode創建ECC200數據矩陣條碼。簡單的2D條碼生成代碼示例。 閱讀更多
發表日期 10月 19, 2025 如何使用VB.NET在Crystal Reports中打印條碼 在VB.NET中使用IronBarcode SDK在Crystal Reports中生成和打印條碼的分步教程,確保可靠的條碼集成。 閱讀更多