IRONBARCODEの使用 C# USBバーコードスキャナーを作成する方法 Jordi Bardia 公開日:9月 29, 2025 Download IronBarcode NuGet Download テキストの検索と置換 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 小売業、倉庫業、在庫管理で働いたことがあるなら、運営をスムーズにするためにバーコードスキャナーがどれほど重要か知っています。 IronBarcodeライブラリとその強力な検証および生成機能を使用すれば、単純なバーコードデータキャプチャを超えた堅牢なC# USBバーコードスキャナアプリケーションを構築できます。 バーコードデータの検証、構造化情報の抽出、さらにはリアルタイムで新しいバーコードを生成することもできます。 本ガイドでは、IronBarcodeをC#で使用したUSBバーコードスキャナの統合方法を示します。 最後には、.NET Frameworkおよび.NETアプリケーションの両方で機能し、在庫管理とアイテム追跡をより効率的にするための堅牢でリアルタイムのスキャンソリューションを手に入れられます。 USBバーコードスキャナーはIronBarcodeとどのように連携するか? ほとんどのUSBバーコードスキャナはHID(ヒューマンインターフェイスデバイス)キーボードウェッジモードで動作し、キーボード入力をエミュレートすることで、ユーザーが簡単にコードをスキャンできます。 バーコードをスキャンすると、スキャナーはバーコードデータを入力し、続けてEnterキーを押します。 IronBarcode enhances this raw input by validating formats, extracting structured data, and enabling immediate バーコードを生成可能にします。 // Capture scanner input and validate with IronBarcode private void txtBarcode_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { string scannedData = txtBarcode.Text; var results = BarcodeReader.Read(GenerateBarcodeImage(scannedData)); if (results.Any()) { ProcessValidBarcode(results.First()); } } } // Capture scanner input and validate with IronBarcode private void txtBarcode_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { string scannedData = txtBarcode.Text; var results = BarcodeReader.Read(GenerateBarcodeImage(scannedData)); if (results.Any()) { ProcessValidBarcode(results.First()); } } } IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel このコードはTextBoxを通じてスキャナの入力をキャプチャし、IronBarcodeを使用して読み取ったデータを有効なバーコードフォーマットとして検証することで、入力を完全に制御します。 バーコードスキャナープロジェクトをどのように設定するか? まず、Microsoft Visual StudioでWindowsフォームアプリケーションを作成し、IronBarcodeライブラリをダウンロードしてください。 次に、NuGetパッケージマネージャコンソールを通じて、次のコマンドを実行してIronBarcodeライブラリをインストールします。 Install-Package BarCode これらの基本的な名前空間をフォームに追加し、ドキュメントで提供されているサンプルも利用してください。 using IronBarCode; using System.Drawing; using System.Linq; using IronBarCode; using System.Drawing; using System.Linq; IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel スキャナの入力をキャプチャするための単一のテキストボックスを備えたシンプルなフォームを作成し、ポート設定が正しく行われていることを確認してください。 フォームがロードされたときに自動的にフォーカスを受け取るようにTextBoxを設定し、USBスキャナーのデータが常にキャプチャされるようにします。 IronBarcodeを使用してスキャンバーコードをどのように検証するか? IronBarcodeはバーコードデータの検証と解析を得意としています。 スキャンされた入力を確認し、有意義な情報を抽出する方法は次の通りです: private void ProcessScannedBarcode(string scannedText) { // Generate temporary barcode image from scanned text var barcode = BarcodeWriter.CreateBarcode(scannedText, BarcodeEncoding.Code128); // Validate by reading back var validationResults = BarcodeReader.Read(barcode.ToBitmap()); if (validationResults.Any()) { var validated = validationResults.First(); // Extract barcode type and value string format = validated.BarcodeType.ToString(); string value = validated.Value; lblStatus.Text = $"Valid {format}: {value}"; // Process based on format if (format.Contains("EAN") || format.Contains("UPC")) { // Product barcode - lookup item ProcessProductCode(value); } } else { lblStatus.Text = "Invalid barcode format"; } } private void ProcessScannedBarcode(string scannedText) { // Generate temporary barcode image from scanned text var barcode = BarcodeWriter.CreateBarcode(scannedText, BarcodeEncoding.Code128); // Validate by reading back var validationResults = BarcodeReader.Read(barcode.ToBitmap()); if (validationResults.Any()) { var validated = validationResults.First(); // Extract barcode type and value string format = validated.BarcodeType.ToString(); string value = validated.Value; lblStatus.Text = $"Valid {format}: {value}"; // Process based on format if (format.Contains("EAN") || format.Contains("UPC")) { // Product barcode - lookup item ProcessProductCode(value); } } else { lblStatus.Text = "Invalid barcode format"; } } IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel このメソッドはスキャンコードの入力をバーコードに変換し、IronBarcodeで読み戻すことにより検証し、信頼性のある参照となります。 バーコードフォーマット(例:Code 128、EAN、UPC)を識別し、それに応じて処理します。 IronBarcodeは多数のフォーマットをサポートし、QRコード、Data Matrix、PDF417、一般的な1Dバーコードすべて対応しています。 スキャンされた入力からレスポンスバーコードを生成する方法は? スキャンデータを変換して新しいバーコードを生成し、ラベリング、追跡、在庫管理に利用します: private void GenerateInventoryLabel(string productCode) { // Create inventory code from scanned product string inventoryCode = $"INV-{DateTime.Now:yyyyMMdd}-{productCode}"; // Generate new barcode with custom styling var inventoryBarcode = BarcodeWriter.CreateBarcode(inventoryCode, BarcodeEncoding.Code128); inventoryBarcode.AddAnnotationTextAboveBarcode(inventoryCode); inventoryBarcode.ResizeTo(300, 100); // Ensure labels folder exists System.IO.Directory.CreateDirectory("labels"); // Save barcode PNG for printing string filePath = $"labels\\{inventoryCode}.png"; inventoryBarcode.SaveAsPng(filePath); // Load a copy into the PictureBox if (pictureBoxReceipt.Image != null) pictureBoxReceipt.Image.Dispose(); pictureBoxReceipt.Image = new System.Drawing.Bitmap(filePath); } // Alternative: Generate QR code for mobile scanning private void CreateQRResponse(string data) { var qrCode = QRCodeWriter.CreateQrCode(data); qrCode.ResizeTo(200, 200); System.IO.Directory.CreateDirectory("labels"); string filePath = $"labels\\QR_{DateTime.Now:yyyyMMddHHmmss}.png"; qrCode.SaveAsPng(filePath); if (pictureBoxQR.Image != null) pictureBoxQR.Image.Dispose(); pictureBoxQR.Image = new System.Drawing.Bitmap(filePath); } private void GenerateInventoryLabel(string productCode) { // Create inventory code from scanned product string inventoryCode = $"INV-{DateTime.Now:yyyyMMdd}-{productCode}"; // Generate new barcode with custom styling var inventoryBarcode = BarcodeWriter.CreateBarcode(inventoryCode, BarcodeEncoding.Code128); inventoryBarcode.AddAnnotationTextAboveBarcode(inventoryCode); inventoryBarcode.ResizeTo(300, 100); // Ensure labels folder exists System.IO.Directory.CreateDirectory("labels"); // Save barcode PNG for printing string filePath = $"labels\\{inventoryCode}.png"; inventoryBarcode.SaveAsPng(filePath); // Load a copy into the PictureBox if (pictureBoxReceipt.Image != null) pictureBoxReceipt.Image.Dispose(); pictureBoxReceipt.Image = new System.Drawing.Bitmap(filePath); } // Alternative: Generate QR code for mobile scanning private void CreateQRResponse(string data) { var qrCode = QRCodeWriter.CreateQrCode(data); qrCode.ResizeTo(200, 200); System.IO.Directory.CreateDirectory("labels"); string filePath = $"labels\\QR_{DateTime.Now:yyyyMMddHHmmss}.png"; qrCode.SaveAsPng(filePath); if (pictureBoxQR.Image != null) pictureBoxQR.Image.Dispose(); pictureBoxQR.Image = new System.Drawing.Bitmap(filePath); } IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel これらのメソッドは、注釈とカスタムサイジングを使用したフォーマットされたバーコードを作成することで、IronBarcodeの生成能力を示します。 QRコードの生成は、IronBarcodeが2Dフォーマットをサポートしていることを示しています。 完全なバーコードスキャンアプリケーションをどのように構築するか? スキャン、検証、生成を組み合わせた完全な例は次の通りです: using IronBarCode; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace UsbBarcodeScanner { public partial class InventoryScanner : Form { private List<string> scannedItems = new List<string>(); public InventoryScanner() { InitializeComponent(); // Wire the KeyDown event handler for scanner input txtScanner.KeyDown += txtScanner_KeyDown; // Focus the scanner TextBox when form loads this.Load += (s, e) => txtScanner.Focus(); } private void txtScanner_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; // Prevents ding or extra chars string input = txtScanner.Text.Trim(); if (string.IsNullOrEmpty(input)) { lblStatus.Text = "Please enter a barcode"; return; } try { // Generate barcode (Code128) var testBarcode = BarcodeWriter.CreateBarcode(input, BarcodeEncoding.Code128); // Add to inventory scannedItems.Add(input); listBoxInventory.Items.Add($"{DateTime.Now:HH:mm:ss} - {input}"); // Generate receipt barcode GenerateReceipt(); lblStatus.Text = "Item added successfully"; } catch (Exception ex) { lblStatus.Text = $"Error: {ex.Message}"; // Fallback: Try IronBarcode's image or PDF scanning try { string backupFile = "backup.pdf"; // path to backup PDF if (File.Exists(backupFile)) { var results = BarcodeReader.ReadPdf(backupFile); if (results.Any()) { var first = results.First(); scannedItems.Add(first.Value); listBoxInventory.Items.Add($"{DateTime.Now:HH:mm:ss} - {first.Value}"); GenerateReceipt(); lblStatus.Text = "Item added via PDF fallback"; } else { lblStatus.Text += " (No barcodes found in backup PDF)"; } } else { lblStatus.Text += " (Backup PDF not found)"; } } catch (Exception fallbackEx) { lblStatus.Text += $" (Fallback failed: {fallbackEx.Message})"; } } } txtScanner.Clear(); txtScanner.Focus(); } private void GenerateReceipt() { string receiptCode = $"RCP{scannedItems.Count:D5}"; var receipt = BarcodeWriter.CreateBarcode(receiptCode, BarcodeEncoding.Code93); receipt.AddAnnotationTextBelowBarcode($"Items: {scannedItems.Count}"); // Ensure labels folder exists Directory.CreateDirectory("labels"); string filePath = $"labels\\{receiptCode}.png"; // Save barcode to file receipt.SaveAsPng(filePath); // Load into PictureBox safely if (pictureBoxReceipt.Image != null) pictureBoxReceipt.Image.Dispose(); pictureBoxReceipt.Image = new Bitmap(filePath); } } } using IronBarCode; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace UsbBarcodeScanner { public partial class InventoryScanner : Form { private List<string> scannedItems = new List<string>(); public InventoryScanner() { InitializeComponent(); // Wire the KeyDown event handler for scanner input txtScanner.KeyDown += txtScanner_KeyDown; // Focus the scanner TextBox when form loads this.Load += (s, e) => txtScanner.Focus(); } private void txtScanner_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; // Prevents ding or extra chars string input = txtScanner.Text.Trim(); if (string.IsNullOrEmpty(input)) { lblStatus.Text = "Please enter a barcode"; return; } try { // Generate barcode (Code128) var testBarcode = BarcodeWriter.CreateBarcode(input, BarcodeEncoding.Code128); // Add to inventory scannedItems.Add(input); listBoxInventory.Items.Add($"{DateTime.Now:HH:mm:ss} - {input}"); // Generate receipt barcode GenerateReceipt(); lblStatus.Text = "Item added successfully"; } catch (Exception ex) { lblStatus.Text = $"Error: {ex.Message}"; // Fallback: Try IronBarcode's image or PDF scanning try { string backupFile = "backup.pdf"; // path to backup PDF if (File.Exists(backupFile)) { var results = BarcodeReader.ReadPdf(backupFile); if (results.Any()) { var first = results.First(); scannedItems.Add(first.Value); listBoxInventory.Items.Add($"{DateTime.Now:HH:mm:ss} - {first.Value}"); GenerateReceipt(); lblStatus.Text = "Item added via PDF fallback"; } else { lblStatus.Text += " (No barcodes found in backup PDF)"; } } else { lblStatus.Text += " (Backup PDF not found)"; } } catch (Exception fallbackEx) { lblStatus.Text += $" (Fallback failed: {fallbackEx.Message})"; } } } txtScanner.Clear(); txtScanner.Focus(); } private void GenerateReceipt() { string receiptCode = $"RCP{scannedItems.Count:D5}"; var receipt = BarcodeWriter.CreateBarcode(receiptCode, BarcodeEncoding.Code93); receipt.AddAnnotationTextBelowBarcode($"Items: {scannedItems.Count}"); // Ensure labels folder exists Directory.CreateDirectory("labels"); string filePath = $"labels\\{receiptCode}.png"; // Save barcode to file receipt.SaveAsPng(filePath); // Load into PictureBox safely if (pictureBoxReceipt.Image != null) pictureBoxReceipt.Image.Dispose(); pictureBoxReceipt.Image = new Bitmap(filePath); } } } IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel このフル機能スキャナアプリケーションは、USBバーコードスキャナからの入力を簡単にキャプチャし、IronBarcodeを使用して各エントリを検証し、リアルタイムの在庫リストを維持することで、データの正確性を主張できます。 スキャンされたアイテムごとにレシートバーコードを自動的に生成し、即時の視覚的フィードバックを提供します。 安全策として、IronBarcodeはハードウェアスキャナが失敗した場合、PDFからバーコードを読み取ることもできます。 For advanced scenarios or troubleshooting, explore community discussions on Stack Overflow or dive into Microsoft’s HID device documentation. エラーハンドリングのベストプラクティス USBスキャナとIronBarcodeを使用するとき: 無効なフォーマット: BarcodeWriterがサポートされていないデータに遭遇した際には例外をキャッチする スキャナの切断: スキャナの取り外しに対応するためにTextBoxのフォーカスマネジメントを実装する データの検証: IronBarcodeのフォーマット固有のエンコーディングを使用してデータの互換性を保証する 生成の失敗: バーコード生成をtry-catchブロックで囲む タイムアウト処理: スキャナとキーボード入力を区別するためのキーストロークタイミング実装を検討する 結論 IronBarcodeは単純なUSBバーコードスキャンを、データを効率的にフィルタリングおよび管理するインテリジェントなデータ処理アプリケーションに変革します。 ハードウェアスキャナーの入力を組み合わせてIronBarcodeの検証、生成、およびフォーマット変換機能により、あらゆる業界での堅牢なスキャニングソリューションを構築できます。 高ボリュームのスキャンを処理する必要がありますか? 展開ニーズに最適なライセンスオプションを検討してください。 C#アプリケーションでプロフェッショナルなバーコードスキャンを実装するための無料トライアルを始めてください。 よくある質問 IronBarcodeとは何であり、それはUSBバーコードスキャナーとどのように関連していますか? IronBarcodeは、USBバーコードスキャニングのための堅牢なC#アプリケーションを開発者が構築できるライブラリです。バーコード検証、データ抽出、およびバーコード生成などの機能を提供します。 IronBarcodeはUSBスキャナーからのバーコードデータを検証できますか? はい、IronBarcodeは、USBスキャナーからキャプチャしたバーコードデータを検証し、C#アプリケーションのデータ整合性と精度を確保します。 IronBarcodeはバーコード生成をどのように扱っていますか? IronBarcodeは、新しいバーコードをオンザフライで生成し、C#アプリケーション内で簡単にバーコードを作成し印刷できるようにします。 IronBarcodeにはUSBバーコードスキャニング用のエラーハンドリングサポートがありますか? はい、IronBarcodeには、USBバーコードスキャニングと処理中に発生する一般的な問題を管理するための包括的なエラーハンドリングが含まれています。 IronBarcodeを使用してスキャンできるバーコードの種類は何ですか? IronBarcodeはQRコード、UPC、Code 39など、多くのバーコードシンボロジーのスキャニングをサポートしており、さまざまなアプリケーションにおいて多用途です。 IronBarcodeはスキャンされたバーコードから構造化情報を抽出できますか? はい、IronBarcodeはスキャンされたバーコードから構造化情報を抽出し、効率的なデータ処理と管理を支援します。 C#でUSBバーコードスキャナーアプリケーションの構築を始めるにはどうすればいいですか? C#でUSBバーコードスキャナーアプリケーションの構築を始めるには、IronBarcodeと提供されたコード例とドキュメントを利用し、開発プロセスをガイドにします。 Jordi Bardia 今すぐエンジニアリングチームとチャット ソフトウェアエンジニア Jordiは、最も得意な言語がPython、C#、C++であり、Iron Softwareでそのスキルを発揮していない時は、ゲームプログラミングをしています。製品テスト、製品開発、研究の責任を分担し、Jordiは継続的な製品改善において多大な価値を追加しています。この多様な経験は彼を挑戦させ続け、興味を持たせており、Iron Softwareで働くことの好きな側面の一つだと言います。Jordiはフロリダ州マイアミで育ち、フロリダ大学でコンピュータサイエンスと統計学を学びました。 関連する記事 公開日 10月 19, 2025 VB.NETでCrystal Reportsでバーコードを印刷する方法 VB.NETを使用したCrystal Reportsでのバーコード生成と印刷。IronBarcode SDKを使用した信頼できるバーコード統合のステップバイステップのチュートリアル。 詳しく読む 公開日 9月 29, 2025 IronBarcodeと.NETのオープンソースバーコードリーダーの比較 IronBarcodeを使用してC#でバーコードを読む方法 詳しく読む 公開日 9月 29, 2025 ASP.NETアプリケーションでバーコードをスキャンする方法 IronBarcodeを使用してASP.NETでバーコードをスキャンする方法を学びます 詳しく読む ASP.NETアプリケーションでバーコードをスキャンする方法IronBarcodeを使用してXamarin...
公開日 10月 19, 2025 VB.NETでCrystal Reportsでバーコードを印刷する方法 VB.NETを使用したCrystal Reportsでのバーコード生成と印刷。IronBarcode SDKを使用した信頼できるバーコード統合のステップバイステップのチュートリアル。 詳しく読む