VS Code can be used free for commercial projects. It is a great IDE for software development and is my preferred IDE, even for embedded projects (STM32, Rasp Pi, etc).
I previously used #Develop but this is no longer updated, and Visual Studio is not free for commercial use.
This page shows how to use VS Code to create a Windows forms application.
Steps:
- Open VS Code in a new empty folder, and open a terminal window.
- dotnet new sln
This will create a new solution.

- dotnet new winforms
This will create a new winforms project.

- dotnet sln add VSCodePlay.csproj
This will add the project to the solution. - View menu -> Command palette -> type “Debug” and choose “.NET : Generate Assets for Build and Debug”
If this fails then perhaps restarting VSCode can fix it. - The Form1.cs containing the partial class Form1 : Form, and the Form1.Designer.cs containing the partial class Form1 are used to define the visual form.
- Save the file UsbCamera.cs from gitlab/secile to the project folder.
- Read the resolution of the webcam through the calls:
int h = UsbCamera.GetVideoFormat(cameraIndex)[formatIndex].Size.Height;
int w = UsbCamera.GetVideoFormat(cameraIndex)[formatIndex].Size.Width; - Create a picturebox of the form, with dimensions matching the video resolution, h x w.
- Create and start the UsbCamera:
_camera = new UsbCamera(cameraIndex, UsbCamera.GetVideoFormat(cameraIndex)[formatIndex]);
_camera.Start(); - Get a still image from the camera. The first time this is done, the UsbCamera may fail, so just do it again and it succeeds.
Set the picturebox image to be what we received from the camera.
var bmp = _camera.GetBitmap();
bmp = _camera.GetBitmap();
this.cameraPictureBox.Image = bmp; - To get video instead of a still image, set up a timer and on each interval read from the camera and save it to the picturebox.
var timer = new System.Timers.Timer(1000 / 30) { SynchronizingObject = this };
timer.Elapsed += (s, ev) => this.cameraPictureBox.Image = _camera.GetBitmap();
timer.Start();
this.FormClosing += (s, ev) => timer.Stop(); - Run a terminal command to build the application:
dotnet build - Press F5 to start a debug session.