but!... comming soon!

About Techinforoad.com

Welcome to Techinforoad.com - my website where I will publish various articles, tutorials and how-tos on Microsoft Business Solutions Dynamics NAV, SQL Server, virtualization technology and more.
Home Programming Visual Basic .NET 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
User Rating: / 2
PoorBest 

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

01

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

02

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:

03

Set the following properties:

TextBox1  
Name txtValue1
TextBox2  
Name txtValue2
Button1  
Name btnPlus
Text +
Button2  
Name btnMinus
Text -
Button3
Name btnMultiply
Text x
Button4  
Name btnDivide
Text /
Label1  
Name lblResult
GroupBox1  
Text MiniCalc

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:



Public Class miniCalc

Private Sub btnPlus_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles btnPlus.Click

lblResult.Text = CInt(txtValue1.Text) + CInt(txtValue2.Text)

End Sub


Private Sub btnMinus_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles btnMinus.Click

lblResult.Text = CInt(txtValue1.Text) - CInt(txtValue2.Text)

End Sub


Private Sub btnMultiply_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles btnMultiply.Click

lblResult.Text = CInt(txtValue1.Text) * CInt(txtValue2.Text)

End Sub


Private Sub btnDivide_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles btnDivide.Click

lblResult.Text = CInt(txtValue1.Text) / CInt(txtValue2.Text)

End Sub


Private Sub GroupBox1_Enter(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles GroupBox1.Enter

lblResult.Text = ""

End Sub
End Class

6)    In the solution explorer right-click on MiniCalc and select Properties:

04

7)    Make sure that the following parameters are set:

05

8)    Now got to Build à Build MiniCalc

06

9)    Now, go to the Bin folder in your project folder. In my case, I saved my MiniCalc project under C:\Projects\:

07

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"

08

13)     Go to Project and click on Add Reference...

09

14)     In the Add Reference window click on the Browse tab, locate MiniCalc.dll file and click OK button:

10

15)     In the Toolbox pane right-click somewhere in the empty space and select Add Tab:

11

16)     Name it My Controls and click Enter

12

17)     Right-click under My Controls and select Choose Items... from the context menus:

13

18)     In the .NET Framework Components tab click Browse.. and locate MiniCalc.dll file.

14

19)     miniCalc.dll will be added to your components collection. Click OK button to close the dialog window.

15

20)     MiniCalc control is now added to My Controls.

16


21)     Drag it to your form:

17


22)     Click F5 to start debugging:

18

In this tutorial we have learned how to create DLL files and use them across other applications.

Download the sample project here (zip, 36Kb).