作成日: 2018/12/06 最終更新日: 2018/12/06
文書種別
使用方法
詳細
C1BarCodeコントロールでは、Imageプロパティを使用してバーコードイメージを作成します。このとき、内部処理的には画面ディスプレイの画面解像度およびコントロールサイズを元に、丸め処理(実際のサイズからピクセル値への変換処理)が行われており、画面解像度が低かったりコントロールサイズが小さかったりすると、解像度による分解能の影響が大きくなってバーコードイメージの線がぼやけるなど画質が粗くなることがあります。
そのため、このバーコードをそのまま印刷するとバーコードリーダーで読み込めないといった現象が発生する可能性があります。これを回避する方法として、次の2通りの手段が考えられます。
(1)C1BarCodeのAutoSizeをFalseに設定し、大きなサイズを指定してバーコードイメージを作成する
C1BarCodeのAutoSizeをFalseに設定し、C1BarCodeコントロールのサイズを拡大してバーコードイメージを生成します。これにより、上述の丸め処理による影響を軽減させることができます。印刷の際には、これを縮小してPrintDocumentに描画し、Printメソッドで印刷を行います。
◎サンプルコード(VB)
◎サンプルコード(C#)
(2)C1BarCodeコントロールの代わりに、FlexReportのBarcodeフィールドを使ってレポートを直接印刷する
FlexReport for WinFormsのBarCodeFieldクラスは、C1BarCodeと同じアセンブリを用いてバーコードを生成しますが、Imageプロパティを経由せず直接レポートにバーコードイメージを描画するため、画面解像度の影響を受けず、印刷してもその影響による画質低下が発生することはありません。
◎サンプルコード(VB)
◎サンプルコード(C#)
そのため、このバーコードをそのまま印刷するとバーコードリーダーで読み込めないといった現象が発生する可能性があります。これを回避する方法として、次の2通りの手段が考えられます。
(1)C1BarCodeのAutoSizeをFalseに設定し、大きなサイズを指定してバーコードイメージを作成する
C1BarCodeのAutoSizeをFalseに設定し、C1BarCodeコントロールのサイズを拡大してバーコードイメージを生成します。これにより、上述の丸め処理による影響を軽減させることができます。印刷の際には、これを縮小してPrintDocumentに描画し、Printメソッドで印刷を行います。
◎サンプルコード(VB)
Imports C1.BarCode
Imports System.Drawing.Printing
Public Class Form1
Dim wBarCode1 As Integer
Dim hBarCode1 As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
wBarCode1 = C1BarCode1.Width
hBarCode1 = C1BarCode1.Height
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
C1BarCode1.CodeType = CodeType.RSS14
C1BarCode1.Text = "1234567890"
' AutoSizeをFalseに設定
C1BarCode1.AutoSize = False
' バーコードサイズを拡大
C1BarCode1.Height = C1BarCode1.Height * 2
C1BarCode1.BarHeight = C1BarCode1.BarHeight * 2
C1BarCode1.Width = C1BarCode1.Width * 2
C1BarCode1.ModuleSize = C1BarCode1.ModuleSize * 2
'PrintDocumentを定義
Dim PrintDocument1 As New System.Drawing.Printing.PrintDocument
AddHandler PrintDocument1.PrintPage, New PrintPageEventHandler(AddressOf PrintDocument1_PrintPage)
'' プレビュー表示
'Dim dlg As New PrintPreviewDialog()
'dlg.Document = PrintDocument1
'dlg.ShowDialog()
'印刷
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
'PrintDocumentのグラフィックオブジェクト作成
Dim gra_Graphic As Graphics = e.Graphics
gra_Graphic.FillRectangle(Brushes.White, e.PageBounds)
' C1BarCodeのバーコードイメージを元のサイズに縮小して描画
gra_Graphic.DrawImage(C1BarCode1.Image, 100, 100, wBarCode1, hBarCode1)
End Sub
End Class
Imports System.Drawing.Printing
Public Class Form1
Dim wBarCode1 As Integer
Dim hBarCode1 As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
wBarCode1 = C1BarCode1.Width
hBarCode1 = C1BarCode1.Height
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
C1BarCode1.CodeType = CodeType.RSS14
C1BarCode1.Text = "1234567890"
' AutoSizeをFalseに設定
C1BarCode1.AutoSize = False
' バーコードサイズを拡大
C1BarCode1.Height = C1BarCode1.Height * 2
C1BarCode1.BarHeight = C1BarCode1.BarHeight * 2
C1BarCode1.Width = C1BarCode1.Width * 2
C1BarCode1.ModuleSize = C1BarCode1.ModuleSize * 2
'PrintDocumentを定義
Dim PrintDocument1 As New System.Drawing.Printing.PrintDocument
AddHandler PrintDocument1.PrintPage, New PrintPageEventHandler(AddressOf PrintDocument1_PrintPage)
'' プレビュー表示
'Dim dlg As New PrintPreviewDialog()
'dlg.Document = PrintDocument1
'dlg.ShowDialog()
'印刷
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
'PrintDocumentのグラフィックオブジェクト作成
Dim gra_Graphic As Graphics = e.Graphics
gra_Graphic.FillRectangle(Brushes.White, e.PageBounds)
' C1BarCodeのバーコードイメージを元のサイズに縮小して描画
gra_Graphic.DrawImage(C1BarCode1.Image, 100, 100, wBarCode1, hBarCode1)
End Sub
End Class
◎サンプルコード(C#)
using C1.BarCode;
using System.Drawing.Printing;
namespace prj_BarCode
{
public partial class Form1 : Form
{
int wBarCode1;
int hBarCode1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
wBarCode1 = c1BarCode1.Width;
hBarCode1 = c1BarCode1.Height;
}
private void button1_Click(object sender, EventArgs e)
{
// バータイプを設定
c1BarCode1.CodeType = CodeType.RSS14;
c1BarCode1.Text = "1234567890";
// AutoSizeをFalseに設定
c1BarCode1.AutoSize = false;
// バーコードサイズを拡大
c1BarCode1.Height = (c1BarCode1.Height * 2);
c1BarCode1.BarHeight = (c1BarCode1.BarHeight * 2);
c1BarCode1.Width = (c1BarCode1.Width * 2);
c1BarCode1.ModuleSize = (c1BarCode1.ModuleSize * 2);
// PrintDocumentを定義
System.Drawing.Printing.PrintDocument PrintDocument1 = new System.Drawing.Printing.PrintDocument();
PrintDocument1.PrintPage += new PrintPageEventHandler(PrintDocument1_PrintPage);
//// プレビュー表示
//PrintPreviewDialog dlg = new PrintPreviewDialog();
//dlg.Document = PrintDocument1;
//dlg.ShowDialog();
// 印刷
PrintDocument1.Print();
}
private void PrintDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
// PrintDocumentのグラフィックオブジェクト作成
Graphics gra_Graphic = e.Graphics;
gra_Graphic.FillRectangle(Brushes.White, e.PageBounds);
// C1BarCodeのバーコードイメージを元のサイズに縮小して描画
gra_Graphic.DrawImage(c1BarCode1.Image, 100, 100, wBarCode1, hBarCode1);
}
}
}
using System.Drawing.Printing;
namespace prj_BarCode
{
public partial class Form1 : Form
{
int wBarCode1;
int hBarCode1;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
wBarCode1 = c1BarCode1.Width;
hBarCode1 = c1BarCode1.Height;
}
private void button1_Click(object sender, EventArgs e)
{
// バータイプを設定
c1BarCode1.CodeType = CodeType.RSS14;
c1BarCode1.Text = "1234567890";
// AutoSizeをFalseに設定
c1BarCode1.AutoSize = false;
// バーコードサイズを拡大
c1BarCode1.Height = (c1BarCode1.Height * 2);
c1BarCode1.BarHeight = (c1BarCode1.BarHeight * 2);
c1BarCode1.Width = (c1BarCode1.Width * 2);
c1BarCode1.ModuleSize = (c1BarCode1.ModuleSize * 2);
// PrintDocumentを定義
System.Drawing.Printing.PrintDocument PrintDocument1 = new System.Drawing.Printing.PrintDocument();
PrintDocument1.PrintPage += new PrintPageEventHandler(PrintDocument1_PrintPage);
//// プレビュー表示
//PrintPreviewDialog dlg = new PrintPreviewDialog();
//dlg.Document = PrintDocument1;
//dlg.ShowDialog();
// 印刷
PrintDocument1.Print();
}
private void PrintDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
// PrintDocumentのグラフィックオブジェクト作成
Graphics gra_Graphic = e.Graphics;
gra_Graphic.FillRectangle(Brushes.White, e.PageBounds);
// C1BarCodeのバーコードイメージを元のサイズに縮小して描画
gra_Graphic.DrawImage(c1BarCode1.Image, 100, 100, wBarCode1, hBarCode1);
}
}
}
(2)C1BarCodeコントロールの代わりに、FlexReportのBarcodeフィールドを使ってレポートを直接印刷する
FlexReport for WinFormsのBarCodeFieldクラスは、C1BarCodeと同じアセンブリを用いてバーコードを生成しますが、Imageプロパティを経由せず直接レポートにバーコードイメージを描画するため、画面解像度の影響を受けず、印刷してもその影響による画質低下が発生することはありません。
◎サンプルコード(VB)
Imports C1.BarCode
Imports C1.Win.FlexReport
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim rpt As C1FlexReport = New C1FlexReport
' バーコードを配置するセクションの設定
rpt.Sections.Detail.Height = 10000
rpt.Sections.Detail.Visible = True
' バーコードフィールドの作成
Dim field1 As BarCodeField = New BarCodeField
field1.AutoHeight = AutoSizeBehavior.GrowAndShrink
field1.AutoWidth = AutoSizeBehavior.GrowAndShrink
' プロパティの設定
field1.Left = 100
field1.Top = 100
field1.Width = 4000
field1.Height = 1000
field1.Font = New Font("MS UI Gothic", 10.0!)
field1.Text = "1234567890"
field1.BarCode = C1.Win.C1Document.BarCodeEnum.RSS14
field1.BarcodeOptions.CaptionGrouping = True
field1.BarcodeOptions.SizeOptions.BarHeight = 700
field1.BarcodeOptions.SizeOptions.ModuleSize = 30
' バーコードをセクションに追加
rpt.Sections.Detail.Fields.Add(field1)
' レポート生成
rpt.Generate
' プレビュー
Dim viewer As C1.Win.FlexViewer.C1FlexViewer = New C1.Win.FlexViewer.C1FlexViewer
viewer.DocumentSource = rpt
Me.Controls.Add(viewer)
viewer.Dock = DockStyle.Fill
' 印刷
rpt.Print
End Sub
End Class
Imports C1.Win.FlexReport
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim rpt As C1FlexReport = New C1FlexReport
' バーコードを配置するセクションの設定
rpt.Sections.Detail.Height = 10000
rpt.Sections.Detail.Visible = True
' バーコードフィールドの作成
Dim field1 As BarCodeField = New BarCodeField
field1.AutoHeight = AutoSizeBehavior.GrowAndShrink
field1.AutoWidth = AutoSizeBehavior.GrowAndShrink
' プロパティの設定
field1.Left = 100
field1.Top = 100
field1.Width = 4000
field1.Height = 1000
field1.Font = New Font("MS UI Gothic", 10.0!)
field1.Text = "1234567890"
field1.BarCode = C1.Win.C1Document.BarCodeEnum.RSS14
field1.BarcodeOptions.CaptionGrouping = True
field1.BarcodeOptions.SizeOptions.BarHeight = 700
field1.BarcodeOptions.SizeOptions.ModuleSize = 30
' バーコードをセクションに追加
rpt.Sections.Detail.Fields.Add(field1)
' レポート生成
rpt.Generate
' プレビュー
Dim viewer As C1.Win.FlexViewer.C1FlexViewer = New C1.Win.FlexViewer.C1FlexViewer
viewer.DocumentSource = rpt
Me.Controls.Add(viewer)
viewer.Dock = DockStyle.Fill
' 印刷
rpt.Print
End Sub
End Class
◎サンプルコード(C#)
using C1.Win.FlexReport;
using C1.BarCode;
namespace Prj_BarCodeOnFlexReport
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
var rpt = new C1.Win.FlexReport.C1FlexReport();
// バーコードを配置するセクションの設定
rpt.Sections.Detail.Height = 10000;
rpt.Sections.Detail.Visible = true;
// バーコードフィールドの作成
var field1 = new C1.Win.FlexReport.BarCodeField();
field1.AutoHeight = AutoSizeBehavior.GrowAndShrink;
field1.AutoWidth = AutoSizeBehavior.GrowAndShrink;
// プロパティの設定
field1.Left = 100;
field1.Top = 100;
field1.Width = 4000;
field1.Height = 1000;
field1.Font = new Font("MS UI Gothic", 10.0f);
field1.Text = "1234567890";
field1.BarCode = C1.Win.C1Document.BarCodeEnum.RSS14;
field1.BarcodeOptions.CaptionGrouping = true;
field1.BarcodeOptions.SizeOptions.BarHeight = 700;
field1.BarcodeOptions.SizeOptions.ModuleSize = 30;
// バーコードをセクションに追加
rpt.Sections.Detail.Fields.Add(field1);
// レポート生成
rpt.Generate();
// プレビュー
C1.Win.FlexViewer.C1FlexViewer viewer = new C1.Win.FlexViewer.C1FlexViewer();
viewer.DocumentSource = rpt;
this.Controls.Add(viewer);
viewer.Dock = DockStyle.Fill;
// 印刷
rpt.Print();
}
}
}
using C1.BarCode;
namespace Prj_BarCodeOnFlexReport
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
var rpt = new C1.Win.FlexReport.C1FlexReport();
// バーコードを配置するセクションの設定
rpt.Sections.Detail.Height = 10000;
rpt.Sections.Detail.Visible = true;
// バーコードフィールドの作成
var field1 = new C1.Win.FlexReport.BarCodeField();
field1.AutoHeight = AutoSizeBehavior.GrowAndShrink;
field1.AutoWidth = AutoSizeBehavior.GrowAndShrink;
// プロパティの設定
field1.Left = 100;
field1.Top = 100;
field1.Width = 4000;
field1.Height = 1000;
field1.Font = new Font("MS UI Gothic", 10.0f);
field1.Text = "1234567890";
field1.BarCode = C1.Win.C1Document.BarCodeEnum.RSS14;
field1.BarcodeOptions.CaptionGrouping = true;
field1.BarcodeOptions.SizeOptions.BarHeight = 700;
field1.BarcodeOptions.SizeOptions.ModuleSize = 30;
// バーコードをセクションに追加
rpt.Sections.Detail.Fields.Add(field1);
// レポート生成
rpt.Generate();
// プレビュー
C1.Win.FlexViewer.C1FlexViewer viewer = new C1.Win.FlexViewer.C1FlexViewer();
viewer.DocumentSource = rpt;
this.Controls.Add(viewer);
viewer.Dock = DockStyle.Fill;
// 印刷
rpt.Print();
}
}
}
旧文書番号
83445