使用 IRONBARCODE 條碼產生器 .NET 教學課程 Curtis Chau 更新:2025年9月1日 下載 IronBarcode NuGet 下載 DLL 下載 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 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中產生條碼? 您可以使用 IronBarcode 庫在 .NET 中產生條碼,方法是在 Visual Studio 中建立一個項目,安裝該庫,設計 UI,然後編寫程式碼來產生和顯示條碼。 條碼庫有哪些安裝方法? 您可以使用套件管理器控制台、NuGet 套件管理器解決方案來安裝 IronBarcode 庫,或直接下載 DLL 並將其新增至您的專案。 條碼產生器應用程式必須具備哪些使用者介面元素? 條碼產生器應用程式的基本使用者介面元素包括兩個標籤、一個用於輸入的富文本框和一個用於顯示生成的條碼圖像的圖片框。 條碼產生功能的編碼涉及哪些步驟? 若要編寫條碼產生功能,請在button1_Click函數中編寫程式碼,使用 IronBarcode 產生條碼,將其儲存為 PNG 格式,並在 PictureBox 中顯示。 使用該庫可以產生哪些類型的條碼? IronBarcode 支援產生各種條碼類型,包括 Code128 和 QRCode 等。 如何在產生的條碼下方新增文字? 您可以使用 IronBarcode 庫中的AddBarcodeValueTextBelowBarcode方法,將條碼的編碼值作為文字新增至影像下方。 使用 IronBarcode 函式庫有哪些優勢? 使用 IronBarcode 可實現高效能、高精度的最佳化條碼生成,提供用戶友好的 API,並且在實際應用中錯誤率低。 在哪裡可以找到條碼庫的詳細文件? IronBarcode 庫的詳細文件和範例可在 IronBarcode 官方網站上找到。 條碼庫目前有任何促銷活動嗎? 是的,目前有促銷活動,購買完整的 Iron Suite 套裝即可享受五個音色庫的價格,相當於兩個音色庫的價格。 如何排查.NET中條碼產生的常見問題? 常見問題通常可以透過確保正確安裝 IronBarcode 庫、檢查 UI 元件是否正確配置以及驗證條碼產生程式碼是否沒有錯誤來解決。 Curtis Chau 立即與工程團隊聊天 技術撰稿人 Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。 相關文章 更新2026年1月22日 ASP.NET 條碼掃描器教學:C# 條碼產生器指南 學習如何使用 IronBarcode 在 ASP.NET 中掃描條碼 閱讀更多 發表日期 2026年1月21日 C# 資料矩陣產生器:IronBarcode 完整指南 C# 資料矩陣條碼產生器教學。學習如何使用 IronBarcode 建立 ECC200 資料矩陣條碼。提供簡單的二維條碼生成程式碼範例。 閱讀更多 發表日期 2026年1月21日 使用 IronBarcode 的 Xamarin 條碼產生器建立專業品質的條碼 使用 IronBarcode 和 Xamarin 條碼產生器,學習如何建立專業品質的條碼。 閱讀更多 如何在 ASP.NET 中使用 C# 列印條碼如何在 C# Windows 應用程式...
發表日期 2026年1月21日 C# 資料矩陣產生器:IronBarcode 完整指南 C# 資料矩陣條碼產生器教學。學習如何使用 IronBarcode 建立 ECC200 資料矩陣條碼。提供簡單的二維條碼生成程式碼範例。 閱讀更多
發表日期 2026年1月21日 使用 IronBarcode 的 Xamarin 條碼產生器建立專業品質的條碼 使用 IronBarcode 和 Xamarin 條碼產生器,學習如何建立專業品質的條碼。 閱讀更多