How to create Windows Forms Softphone using C#?

This guide introduces how to develop softphones with Graphical User Interface (GUI), how to implement phone functions with it. You can even execute call control commands by using only a few buttons on a software telephone.

What is Windows Forms? When does it used?

Windows Forms (WinForms) is the name given to the graphical application programming interface (API) included as a part of Microsoft .NET Framework, providing access to native Microsoft Windows interface elements by wrapping the extant Windows API in managed code.

Windows Forms is used to develop GUIs (Graphical User Interface), which are making the applications' usage much more easier to handle, and you can even see every results etc. on graphical layouts.
You can perform actions by clicking buttons etc., instead of writing line of commands.

How to develop Windows Froms softphone using C#?

After you've opened a new Visual Studio Windows Forms Application project, you need to add reference to ozeki.dll, which you can download from the website.

Step 1 - Implementing softphone functions

Before you begin the GUI's development, you have to implement the main steps, which you did in the case of the console softphone development.
Like in the case of the console applications, you should add the new lines to the using sections in order to use the tools provided by Ozeki VoIP SIP SDK as they were in the same namespace.

You have define the main tools for the softphone, for example: ISoftPhone, IPhoneLine, IPhoneCall, Microphone and Speaker objects. You will need all of the instances and objects you've used in the case of a console application.

A background thread needs to be created to handle the GUI interface. So, when an event occurs, you can update the GUI element in the same time by using an other thread.

You need to subscribe to and handle the call and phone line events, for example: when errors or changes occur. You also need to handle incoming calls.

Step 2 - Creating softphone GUI

After the softphone's basic elements have been created, you can start to create the Graphical User Interface. Usually, GUIs are look like an ordinary telephone; they have ten numeric buttons (0-9), 2 special character buttons (* and #), a Pick Up and a Hang Up button, some special buttons (Hold, Transfer etc.), and a display.

First of all, place the main objects: the display (a TextBox or Label object is recommended), the numeric buttons, the special buttons, and the Pick Up and Hang Up buttons on your GUI.

Since you have already implemented the main functions of your softphone, you just have to connect them with your GUI;

  • numeric and special buttons: each of these buttons should add a character to the dialed number. In order to do it, you have several options, for example you can add the characters to the display TextBox's Text field, and that field will be the "called number" as well. It's recommended to implement this function this way, since you would even see the dialed number in the same time, and you wouldn't use a string for the purpose which is already implemented.
  • Pick Up button: with this button you can accept the incoming calls and dial the number, set by the numeric and special buttons (or in the text field, you can even write the number from your keyboard).
  • Hang Up button: with this button you can clear the dialed number's string, you can hang up calls, and you can rejet them.

To the display TextBox you can even set the option to show the phone line's or the call's states, but you can even create separated labels to them, so you would always see the actual states.

Step 3 - Creating special buttons for call control

You can make and accept calls now, but in most of the cases users would like to be able to control calls. For this purpose, you can create methods, implement features from the Softphone Development Basics and render them to buttons (or you can even create your own functions and features, which could even use special graphical elements).

There are several popular functions to be implement, for example: Hold/Unhold, Transfer, Forward, Redial etc.
To implement these functions you will need a button for each of them (please note that, Hold/Unhold function will need only one button, since they are switching each other).

Windows Froms softphone example in C#

You can find three well-detailed step-by-step guides with simple examples and video tutorials within the Training chapter. The series starts with the Video 1 - SIP registration.


Related Pages

More information