
| VB.NET Tutorial: Creating a custom DLL (Dynamic Link Library) in Visual Basic .NET |
|
VB.NET Tutorial: Creating a custom DLL (Dynamic Link Library) in Visual Basic .NET
One of the best programming practices is to use DLL (Dynamic Link Library) files to re-use your code and controls across your applications. In this tutorial I will show you how to create a sample DLL file in Visual Basic .NET Professional edition and attach it to a new application. 1) Create a new project, select Windows Forms Control Library and name it MiniCalc
2) You will see that the new UserControl1.vb is added to your project. Right-click on the UserControl1.vb and select Rename from the menu. Name it MiniCalc.vb
3) Go to the Toolbox and add 1 groupbox, 2 textboxes, 4 buttons and 1 label. Align them on the control as on the following image:
Set the following properties:
4) Right-click on the form and select View Code. You will see the following lines of code in the editor: Public Class miniCalc
End Class 5) Edit the code to make it as follows:
6) In the solution explorer right-click on MiniCalc and select Properties:
7) Make sure that the following parameters are set:
8) Now got to Build à Build MiniCalc
9) Now, go to the Bin folder in your project folder. In my case, I saved my MiniCalc project under C:\Projects\:
10) Copy the MiniCalc.dll to any other directory where you want to store your final DLLs. It's always a good idea to keep your DLL project in case if you will need to modify it in the future. In my case I will copy MiniCalc.dll under C:\My DLLs\ folder. 11) Close MiniCalc project. 12) Create a new Windows Forms Application project and name it "Mini Calculator"
13) Go to Project and click on Add Reference...
14) In the Add Reference window click on the Browse tab, locate MiniCalc.dll file and click OK button:
15) In the Toolbox pane right-click somewhere in the empty space and select Add Tab:
16) Name it My Controls and click Enter
17) Right-click under My Controls and select Choose Items... from the context menus:
18) In the .NET Framework Components tab click Browse.. and locate MiniCalc.dll file.
19) miniCalc.dll will be added to your components collection. Click OK button to close the dialog window.
20) MiniCalc control is now added to My Controls.
21) Drag it to your form:
22) Click F5 to start debugging:
In this tutorial we have learned how to create DLL files and use them across other applications. Download the sample project here (zip, 36Kb).
|