转至元数据结尾
转至元数据起始

本节将详细介绍一些ComponentOne BarCode for WinForms的功能本快速入门将通过快速带您浏览如何向您的工程添加C1BarCode以及设置C1BarCode的外观和行为设置。在快速入门中创建的工程将向您演示ComponentOne BarCode for WinForms中各种可用的编码。有关可用的编码的更多信息,参见支持的编码

步骤一:设置窗体

首先,我们将向窗体添加C1BarCode并设置该工程。完成以下步骤:

  1. 创建一个新的.NET工程。
  2. 从工具栏,在窗体上添加下列控件:

两个GroupBox控件
十个RadioButton控件一个文本框控件
一个命令按钮
一个C1BarCode 控件

  1. 设置以下控件的文本属性,并按照如下图像排布这些控件:

    名称

    文本属性

    GroupBox1

    Encoding Type

    GroupBox2

    Bar Code Text

    Button1

    Submit

    RadioButton1

    CodeBar

    RadioButton2

    Code128

    RadioButton3

    Code39

    RadioButton4

    Code93

    RadioButton5

    CodeI2of5

    RadioButton6

    Ean13

    RadioButton7

    Ean8

    RadioButton8

    PostNet

    RadioButton9

    UpcA

    RadioButton10

    UpcE

  2. 在属性窗体中,设置C1BarCode1的BackColor属性的值为Transparent。
  3. 调整C1BarCode1控件的大小。

你刚刚完成使用BarCode for WinForms的第一步。继续下一步,向工程添加代码。

步骤二:将代码添加到项目

在上一步中您已经设置了窗体并向工程添加了一个C1BarCode,您将继续向工程添加代码。
完成以下步骤:
双击"Button1"切换到代码视图,添加Button1_Click事件。将下面的代码添加到Button1_Click事件处理,以设置
!worddavb869ddfb9e604ada2e67cbb2dc078060.png|height=10,width=14!C1BarCode1的文本为TextBox1中间输入的文本。
Visual Basic

Visual Basic

C1BarCode1.Text = TextBox1.Text

C#

C#

c1BarCode1.Text = TextBox1.Text;

添加下面的代码来处理单选按钮选择行为:

注意:您必须向Form代码的开始添加 Imports C1.Win.C1BarCode(Visual Basic 工程)或者using C1.Win.C1BarCode(C#工程)以便使得以下代码正常工作。

Visual Basic

Visual Basic

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles RadioButton1.CheckedChanged
C1BarCode1.CodeType = CodeTypeEnum.Codabar
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles RadioButton2.CheckedChanged
C1BarCode1.CodeType = CodeTypeEnum.Code128
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles RadioButton3.CheckedChanged
C1BarCode1.CodeType = CodeTypeEnum.Code39
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles RadioButton4.CheckedChanged
C1BarCode1.CodeType = CodeTypeEnum.Code93
End Sub
Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles RadioButton5.CheckedChanged
C1BarCode1.CodeType = CodeTypeEnum.CodeI2of5
End Sub
Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles RadioButton6.CheckedChanged
C1BarCode1.CodeType = CodeTypeEnum.Ean13
End Sub
Private Sub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles RadioButton7.CheckedChanged
C1BarCode1.CodeType = CodeTypeEnum.Ean8
End Sub
Private Sub RadioButton8_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles RadioButton8.CheckedChanged
C1BarCode1.CodeType = CodeTypeEnum.PostNet
End Sub
Private Sub RadioButton9_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles RadioButton9.CheckedChanged
C1BarCode1.CodeType = CodeTypeEnum.UpcA
End Sub
Private Sub RadioButton10_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles RadioButton10.CheckedChanged
C1BarCode1.CodeType = CodeTypeEnum.UpcE
End Sub
C#

C#

private void radioButton1_CheckedChanged(object sender, System.EventArgs e) { c1BarCode1.CodeType = CodeTypeEnum.Codabar; } private void radioButton2_CheckedChanged(object sender, System.EventArgs e) { c1BarCode1.CodeType = CodeTypeEnum.Code128; } private void radioButton3_CheckedChanged(object sender, System.EventArgs e) { c1BarCode1.CodeType = CodeTypeEnum.Code39; } private void radioButton4_CheckedChanged(object sender, System.EventArgs e) { c1BarCode1.CodeType = CodeTypeEnum.Code93; } private void radioButton5_CheckedChanged(object sender, System.EventArgs e) { c1BarCode1.CodeType = CodeTypeEnum.CodeI2of5; } private void radioButton6_CheckedChanged(object sender, System.EventArgs e) { c1BarCode1.CodeType = CodeTypeEnum.Ean13; } private void radioButton7_CheckedChanged(object sender, System.EventArgs e) { c1BarCode1.CodeType = CodeTypeEnum.Ean8; } private void radioButton8_CheckedChanged(object sender, System.EventArgs e) { c1BarCode1.CodeType = CodeTypeEnum.PostNet; } private void radioButton9_CheckedChanged(object sender, System.EventArgs e) { c1BarCode1.CodeType = CodeTypeEnum.UpcA; } private void radioButton10_CheckedChanged(object sender, System.EventArgs e) { c1BarCode1.CodeType = CodeTypeEnum.UpcE;
}

你刚刚完成ComponentOne BarCode for WinForms快速入门的第二步。继续下一步,运行并查看工程运行结果。

步骤三:运行项目

现在我们已经设置好了工程并添加了代码,我们将运行该工程并查看由ComponentOne BarCode for WinForms支持的不同编码。
完成以下步骤:

  1. 运行该项目并选择CodeBar单选按钮。
  2. 输入一个数字的字符串,例如1234,在文本框中,点击提交按钮。

条码现在看起来类似于下面这样:

  1. 选择不同的单选按钮改变编码类型,您可以注意到C1BarCode条形码的外观将发生变化。
  2. 尝试输入您的名字或者其他不同的字母和数字字符组成的字符串,以查看不同的编码类型能够接受哪些类型的字符:


请注意,某些编码有一个字符最小长度的需求,同时有些编码只对数字类型的值有效。关于编码的更多信息,参见支持的编码
到此我们结束ComponentOne BarCode for WinForms快速入门章节。

  • 无标签