コードの作成
コーディングはそんなに難しくありません。2つのComboBoxとTextBoxコントロールの値を連結し、GcBarCodeコンポーネントのValueプロパティにセットします。そして、CreateBitmapメソッドを実行し、バーコードをビットマップに保存します。
保存するファイル名は、「BarCode1.bmp」「BarCode2.bmp」と、バーコードを連続して作成できるように連番を振ったファイル名にします。
CreateBitmapメソッドは、引数に画像解像度のDPI値を指定できますので、ここでは120DPIのビットマップファイルを作成するようにしています。作成したビットマップはImageオブジェクトとして変数に格納し、Saveメソッドを実行してファイルに保存します。
なお、コード作成の際は、GrapeCity.Win.BarCode名前空間をインポートしてください。
Imports GrapeCity.Win.BarCode
Public Class Form1
Private icount As Integer = 1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me.ComboBox1.Items
.Add("101")
.Add("102")
.Add("103")
.Add("201")
.Add("202")
.Add("203")
.Add("301")
.Add("302")
End With
With Me.ComboBox2.Items
.Add("01")
.Add("02")
.Add("03")
.Add("04")
.Add("05")
.Add("06")
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim codenumber As String
codenumber = ComboBox1.Text & ComboBox2.Text & TextBox1.Text
TextBox2.Text = codenumber
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
With GcBarCode1
.Type = GrapeCity.Win.BarCode.ValueType.BarType.JAN13
.Value = TextBox2.Text
End With
Dim imgBarcode1 As Image = GcBarCode1.CreateBitmap(120)
Dim fname As String = "j:\barcode\BarCode" & icount & ".bmp"
imgBarcode1.Save(fname, System.Drawing.Imaging.ImageFormat.Bmp)
icount += 1
End Sub
End Class
using GrapeCity.Win.BarCode;
namespace mybarcode_cs
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int icount = 1;
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("101");
comboBox1.Items.Add("102");
comboBox1.Items.Add("103");
comboBox1.Items.Add("201");
comboBox1.Items.Add("202");
comboBox1.Items.Add("203");
comboBox1.Items.Add("301");
comboBox1.Items.Add("302");
comboBox2.Items.Add("01");
comboBox2.Items.Add("02");
comboBox2.Items.Add("03");
comboBox2.Items.Add("04");
comboBox2.Items.Add("05");
comboBox2.Items.Add("06");
}
private void button1_Click(object sender, EventArgs e)
{
string codenumber;
codenumber = comboBox1.Text + comboBox2.Text + textBox1.Text;
textBox2.Text = codenumber;
}
private void button2_Click(object sender, EventArgs e)
{
gcBarCode1.Type = GrapeCity.Win.BarCode.ValueType.BarType.JAN13;
gcBarCode1.Value = textBox2.Text;
Image imgBarcode1 = gcBarCode1.CreateBitmap(120);
string fname = "j:/barcode/BarCode" + icount + ".bmp";
imgBarcode1.Save(fname, System.Drawing.Imaging.ImageFormat.Bmp);
icount++;
}
}
}
Service Pack 1について
なお、PlusPak for Windows Forms 5.0Jの最新版であるSP1では、新たに「GS1 DataBar」(RSSシンボル)にも対応しています。これにあわせ、Typeプロパティに次のものが追加されています。
| メンバ名 | 説明 |
|---|---|
| 22 - RSS14 | RSS14(GS1 DataBar) |
| 24 - RSS14Stacked | RSS14 Stacked(GS1 DataBar Stacked) |
| 25 - RSS14StackedOmnidirectional | RSS14 Stacked Omnidirectional(GS1 DataBar Stacked Omnidirectional) |
| 23 - RSS14Truncated | RSS14 Truncated(GS1 DataBar Truncated) |
| 26 - RSSExpanded | RSS Expanded(GS1 DataBar Expanded) |
| 27 - RSSExpandedStacked | RSS Expanded Stacked(GS1 DataBar Expanded Stacked) |
まとめ
GcBarCodeコンポーネントは、サンプルプログラムを見てお分かりのように、とても簡単にバーコードを作成します。在庫管理や売り上げ管理、固定資産管理など、今やバーコードは当たり前のようになっているので、バーコード作成のアプリケーションを自社開発するのであれば、このGcBarCodeコンポーネントはとても大きな威力を発揮すると思います。
今回は、ドロップダウンリストから倉庫・棚・商品の番号からバーコードを作成する簡単な機能にしていますが、バーコードにするデータをExcelのワークシートで一覧表にし、一気にバーコードを作成する、などということも可能です。ぜひ試してみてください。

