This tutorial is all about How to Make a Services Calculator and Discount in VB.Net. With this tutorial you can Make a Services Calculator and Discount in VB.Net. easily. So let’s get started
- First is open the Visual Basic, Select File on the menu, then click New and create a new project.
- Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK
- Design your form like this just like what I’ve shown you below.
Add 5 TextBoxes, 8 Labels & 4 Buttons from the Toolbox.
- After Designing your form, Add this code to the button.
- Calculate Button Code.
[vbnet]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Label5.Text = “Sub Total: ” & (Val(TextBox1.Text) + Val(TextBox2.Text) + _
Val(TextBox3.Text) + Val(TextBox4.Text))
Label7.Text = “Total: ” & (Val(TextBox1.Text) + Val(TextBox2.Text) _
+ Val(TextBox3.Text) + Val(TextBox4.Text)) – (Val((Val(TextBox1.Text) _
+ Val(TextBox2.Text) + Val(TextBox3.Text) _
+ Val(TextBox4.Text))) * Val(TextBox5.Text / 100))
Label8.Text = “Discount: ” & (Val((Val(TextBox1.Text) + Val(TextBox2.Text) _
+ Val(TextBox3.Text) + Val(TextBox4.Text))) * Val(TextBox5.Text / 100))
Catch ex As Exception
MsgBox(“Please Enter Valid Inputs”)
End Try
End Sub
[/vbnet] - Clear Button Code.
[vbnet]
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
Label5.Text = “Sub Total:”
Label8.Text = “Discount:”
Label7.Text = “Total:”
End Sub
[/vbnet] - Exit Button Code.
[vbnet]
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End
End Sub
[/vbnet] - Print Button Code
[vbnet]
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim g As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
formImage = New Bitmap(s.Width, s.Height, g)
Dim mg As Graphics = Graphics.FromImage(formImage)
Dim dc1 As IntPtr = g.GetHdc
Dim dc2 As IntPtr = mg.GetHdc
Dim widthDiff As Integer = (Me.Width – Me.ClientRectangle.Width)
Dim heightDiff As Integer = (Me.Height – Me.ClientRectangle.Height)
Dim borderSize As Integer = widthDiff \ 2
Dim heightTitleBar As Integer = heightDiff – borderSize
BitBlt(dc2, 0, 0, Me.ClientRectangle.Width + widthDiff, Me.ClientRectangle.Height _
+ heightDiff, dc1, 0 – borderSize, 0 – heightTitleBar, 13369376)
g.ReleaseHdc(dc1)
mg.ReleaseHdc(dc2)
pd.Print()End Sub
[/vbnet] - Then, Add this Following Declarations.
[vbnet]
Private WithEvents pd As Printing.PrintDocument
Dim formImage As Bitmap
Private Declare Function BitBlt Lib “gdi32.dll” Alias “BitBlt” _
(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
ByVal nYDest As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Long
[/vbnet] - After that, Add This Following Sub.
[vbnet]
Private Sub pd_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage
e.Graphics.DrawImage(formImage, 100, 100)
End Sub
[/vbnet] - Finally, Add the Following to the Form Load Event.
[vbnet]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
pd = New Printing.PrintDocument
Me.StartPosition = FormStartPosition.CenterScreenEnd Sub[/vbnet] - Click F5 to run the Program.
Output:
If you have any comments or suggestion about on How to Make a Services Calculator and Discount in VB.Net, Please Feel Free to contact our webpage.
Download How to Make a Services Calculator and Discount in VB.Net Code Here
Other articles you might read also: