# Step 2: Adding Code to the Project

## Content

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](/componentone/api/win/online-barcode/dotnet-api/C1.Win.Barcode.10/C1.Win.BarCode.C1BarCode.html), add the following code.

    ```vbnet
    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
    ```

    ```csharp
    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.

    ```vbnet
    Private Sub cbCodeType_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbCodeType.SelectedIndexChanged
        C1BarCode1.CodeType = DirectCast(cbCodeType.SelectedValue, CodeType)
    End Sub
    ```

    ```csharp
    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.

    ```vbnet
    Private Sub tbText_TextChanged(sender As Object, e As EventArgs) Handles tbText.TextChanged
        C1BarCode1.Text = tbText.Text
    End Sub
    ```

    ```csharp
    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.