Getting started in Visual C#
Top  Previous  Next

This chapter shows you how to get started with ActiveUSB control in Visual C#. With just a few mouse clicks and a few lines of code, you will be able to display a live video image in your C# program and report a value of a pixel pointed by a mouse cursor in real time.
.
Creating the Project

In the .NET development environment select New -> Project. The New Project Dialog box will appear. Select Visual C# projects on the left and Windows Application on the right. In the Name filed below type the name of your application, for instance MyActiveUSB and click OK . The project will be created, and the main application form will be displayed for editing.

Creating the Control

In the Toolbox select Components. From the Tools menu select Choose Items...-> COM Components and then select ActiveUSB Class from the list. You will see ActiveUSB icon appear at the bottom of the toolbox.

clip0066

Click the ActiveUSB icon in the Toolbox and draw a rectangular area on the form. A rectangle with the text "ActiveUSB Control" will appear on the form, and the Properties window on the right will display ActiveUSB's properties.

Selecting the Camera

In the properties window, click the Camera property. The list box will display all USB3 Vision™ compatible cameras connected to your system. Select the one you intend to use:

clip0068


Selecting the Pixel Format

In the Properties window, click the Format property. The list box will display all pixel formats available for the chosen camera. Select the one you intend to use:

clip0069


Modifying the Control's appearance

In the Properties window set the Edge and ScrollBars fields to "Yes"

clip0071


Adding the Start button

In the Toolbox select Windows Form , click on the Button icon and then draw a rectangular area on the program dialog. A button "Button1" will appear. Go to the Property window and change the Text property to "Start". Double click on the button. A new member function button1_Click will be added to the Form1 source window. Insert one line to the function body:

private void
button1_Click(object sender, System.EventArgs e)
      {
         axActiveUSB1.Acquire=true
;
      }

This will activate continuous acquisition when the button is clicked.


This will activate continuous acquisition when the button is clicked.


Adding text boxes

In the Toolbox click on the TextBox icon and then draw a small rectangular area on the program dialog. Repeat this two more times. Your final design of the main form will be similar to this:

clip0072


Adding the MouseMove event

Click on the ActiveUSB control on the main form. In the Property window click the Event button. In the list of events double-click the MouseMoveEvent .

clip0074

The new event handler axActiveUSB1_MouseMoveEvent will be added to the source code. Add the following lines to the body of the function:

private
void axActiveUSB1_MouseMoveEvent(object sender, AxActiveUSBLib._IActiveUSBEvents_MouseMoveEvent e)
      {
         textBox1.Text=ToString(e.x);
         textBox2.Text=e.y;
         textBox3.Text=axActiveUSB1.GetPixel(e.x,e.y);

      }

Running the application

Close the design window. From the Debug menu of the development environment select Start or press F5. This will build and run the application. The application dialog will appear on the screen with a black image window and empty text boxes. Click the Start button to activate the continuous video acquisition and move the mouse cursor over the image window. You are now able to watch and scroll the live image and analyze pixel coordinates and values - all in real time!

Note - make sure to close the design window with the form containing ActiveUSB control before running your application, or otherwise the IDE will maintain the exclusive control over the camera and will not allow your application to display the video.