ComponentOne BarCode for WinForms
BarCode for WinForms Quick Start / Step 2: Adding Code to the Project
In This Topic
    Step 2: Adding Code to the Project
    In This Topic

    To add code to your project, complete the following steps:

    1. Add namespace Imports C1.BarCode (Visual Basic projects) or using C1.BarCode (C# projects).
    2. Double-click Form1 to create Form1_Load event and switch to the code view. To set the default text of the TextBox and to populate the ComboBox control with the code types available in C1BarCode, add the following code.       
      Visual Basic
      Copy Code
      Dim types As Array = [Enum].GetValues(GetType(CodeType))
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          tbText.Text = "HELLO WORLD!"
          cbCodeType.DataSource = types
          cbCodeType.SelectedIndex = Array.IndexOf(types, CodeType.Code39)
          cbCodeType.Select()
      End Sub
      
      C#
      Copy Code
      Array types = Enum.GetValues(typeof(CodeType));
       private void Form1_Load(object sender, EventArgs e)
      {
          tbText.Text = "HELLO WORLD!"; 
          cbCodeType.DataSource = types;
          cbCodeType.SelectedIndex = Array.IndexOf(types, CodeType.Code39);
          cbCodeType.Select();
      }
      
    3. Click ComboBox on the form. From the events in the Property window, double-click SelectedIndexChanged to create cbCodeType_SelectedIndexChanged event and add following code.
      Visual Basic
      Copy Code
      Private Sub cbCodeType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbCodeType.SelectedIndexChanged
          C1BarCode1.CodeType = DirectCast(cbCodeType.SelectedValue, CodeType)
      End Sub
      
      C#
      Copy Code
      private void cbCodeType_SelectedIndexChanged(object sender, EventArgs e)
      {
          c1BarCode1.CodeType = (CodeType)cbCodeType.SelectedValue;
      }
      
    4. Click the TextBox control on the form. From the events in the Property window, double-click TextChanged to create the tbText_TextChanged event and add following code to the event.
      Visual Basic
      Copy Code
      Private Sub tbText_TextChanged(sender As Object, e As EventArgs) Handles tbText.TextChanged
          C1BarCode1.Text = tbText.Text
      End Sub
      
      C#
      Copy Code
      private void tbText_TextChanged(object sender, EventArgs e)
      {
          c1BarCode1.Text = tbText.Text;
      }       
      

    In this step, you added functionality to the controls. In the next step, you will run the project and observe runtime interactions.