This post explains how to add a reference to a library in Windows Forms Application.
By default when we create a new Windows Forms Application, the visual studio adds references to only needed libraries to run a windows form application.
In Solution Explorer, References folder contains a list of referenced libraries.
By default, visual studio adds the list of libraries shown in the picture to win form application when you create a new project.
Depending on application requirements the application requires extra libraries (internal or external) to perform some tasks. In this case we have to add a reference to the required libraries.
Follow these simple steps to add a reference to a library for example "System.Speech". This library contains members which supports in speech related tasks.
1. Create a new project of type "Windows Forms Application" from Windows Desktop template with a name "AddSpeechRef".
2. In Solution Explorer, right-click on References folder, Click on "Add Reference" as shown here.
3. From Reference Manager dialog, enter "Speech" in search box, depending on targeted .Net Framework (here targeted .Net Framework 4.0), the corresponding library version will be shown in search results.
Select a check-box "System.Speech" and click OK.
At this point we have added a reference successfully.
4. Simply adding a reference to our application is not sufficient. To use members of added library, we have to add a namespace of library with a keyword "using".
In Form1.cs, add a line "using System.Speech.Synthesis" as shown below. Now we can use all members of the library in application.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Speech.Synthesis; //add namespace in order to utilize members of library namespace AddSpeechRef { public partial class Form1 : Form { public Form1() { InitializeComponent(); } } }
In case of external libraries, in Reference Manager dialog, click on Browse and locate the library files (*.dll) on local machine and click on Add.