C# 从winforms应用程序打印条形码

C# 从winforms应用程序打印条形码,c#,winforms,printing,barcode,C#,Winforms,Printing,Barcode,我希望在winforms应用程序中使用正常的打印设备打印条形码,而不是通过类似ZPL的语言。我可以打印任何东西,只是不能打印普通条形码 using (PrintDocument pd = new PrintDocument()) { pd.PrintController = new StandardPrintController(); pd.PrinterSettings.PrinterName = "Printer"; pd.PrintPage += new Print

我希望在winforms应用程序中使用正常的打印设备打印条形码,而不是通过类似ZPL的语言。我可以打印任何东西,只是不能打印普通条形码

using (PrintDocument pd = new PrintDocument())
{
    pd.PrintController = new StandardPrintController();
    pd.PrinterSettings.PrinterName = "Printer";
    pd.PrintPage += new PrintPageEventHandler(pd_PrintLabel);
    pd.Print();
}

private void pdPrintLabel(object sender, PrintPageEventArgs ev)
{
    Graphics g = ev.Graphics;

    using (Font f = new Font(FontFamily.GenericSansSerif, 6))
    {
       g.DrawString(????????? what to do for barcode????);
    }
}
我们使用的是:


我使用了Infragistics UltraCode128Barcode1条形码,它对我很有用

  Private Sub btnprintbarcodes_Click(sender As Object, e As EventArgs) Handles btnprintbarcodes.Click

        PrintDocument1.Print()
    End Sub

   Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
        e.PageSettings.PrinterSettings.PrinterName = ApplicationHelper.GetApplicationSettingValue("Barcode_Printer_Name")
        Dim barcodeImageFile As String = String.Empty
        If UltraCode128Barcode1.Data IsNot Nothing Then
            barcodeImageFile = String.Concat(Path.GetTempPath(), Guid.NewGuid(), ".tiff")
            UltraCode128Barcode1.SaveTo(barcodeImageFile, ImageFormat.Tiff)
            Dim barcodeimage = Image.FromFile(barcodeImageFile)
            e.Graphics.DrawImage(barcodeimage, 0, 0)
            e.Graphics.DrawString(UltraCode128Barcode1.Data, New Font("arial", 8), New SolidBrush(Color.Black), 0, 50)
        End If
        If (File.Exists(barcodeImageFile)) Then
            'File.Delete(barcodeImageFile)
        End If
    End Sub

  Private Sub PrintDocument1_BeginPrint(sender As Object, e As PrintEventArgs) Handles PrintDocument1.BeginPrint
        ApplicationHelper.ShowGeneralDialog("The Program is about to print barcode(s).Make sure your barcode printer is on and loaded")
    End Sub

您的
条码数据
看起来如何?(其代表)
void printDoc()
{

    PrintDocument document = new PrintDocument();
    BarcodeDraw bdraw = BarcodeDrawFactory.GetSymbology(BarcodeSymbology.Code128);
    Image barcodeImage = bdraw.Draw("PO7120172733039800", 50);

    document.PrintPage += delegate(object sender, PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(barcodeImage, 0, 0);
        e.Graphics.DrawString("PO7120172733039800", new Font("arial", 8), new SolidBrush(Color.Black),0,50);
    };
    document.Print();
}
  Private Sub btnprintbarcodes_Click(sender As Object, e As EventArgs) Handles btnprintbarcodes.Click

        PrintDocument1.Print()
    End Sub

   Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
        e.PageSettings.PrinterSettings.PrinterName = ApplicationHelper.GetApplicationSettingValue("Barcode_Printer_Name")
        Dim barcodeImageFile As String = String.Empty
        If UltraCode128Barcode1.Data IsNot Nothing Then
            barcodeImageFile = String.Concat(Path.GetTempPath(), Guid.NewGuid(), ".tiff")
            UltraCode128Barcode1.SaveTo(barcodeImageFile, ImageFormat.Tiff)
            Dim barcodeimage = Image.FromFile(barcodeImageFile)
            e.Graphics.DrawImage(barcodeimage, 0, 0)
            e.Graphics.DrawString(UltraCode128Barcode1.Data, New Font("arial", 8), New SolidBrush(Color.Black), 0, 50)
        End If
        If (File.Exists(barcodeImageFile)) Then
            'File.Delete(barcodeImageFile)
        End If
    End Sub

  Private Sub PrintDocument1_BeginPrint(sender As Object, e As PrintEventArgs) Handles PrintDocument1.BeginPrint
        ApplicationHelper.ShowGeneralDialog("The Program is about to print barcode(s).Make sure your barcode printer is on and loaded")
    End Sub