How to Make a Services Calculator and Discount in VB.Net

0
82

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.
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. Try
    3. Label5.Text = "Sub Total: " & (Val(TextBox1.Text) + Val(TextBox2.Text) + _
    4. Val(TextBox3.Text) + Val(TextBox4.Text))
    5. Label7.Text = "Total: " & (Val(TextBox1.Text) + Val(TextBox2.Text) _
    6. + Val(TextBox3.Text) + Val(TextBox4.Text)) - (Val((Val(TextBox1.Text) _
    7. + Val(TextBox2.Text) + Val(TextBox3.Text) _
    8. + Val(TextBox4.Text))) * Val(TextBox5.Text / 100))
    9. Label8.Text = "Discount: " & (Val((Val(TextBox1.Text) + Val(TextBox2.Text) _
    10. + Val(TextBox3.Text) + Val(TextBox4.Text))) * Val(TextBox5.Text / 100))
    11. Catch ex As Exception
    12. MsgBox("Please Enter Valid Inputs")
    13. End Try
    14. End Sub
  • Clear Button Code.
    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    2. TextBox1.Clear()
    3. TextBox2.Clear()
    4. TextBox3.Clear()
    5. TextBox4.Clear()
    6. TextBox5.Clear()
    7. Label5.Text = "Sub Total:"
    8. Label8.Text = "Discount:"
    9. Label7.Text = "Total:"
    10. End Sub
  • Exit Button Code.
    1. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    2. End
    3. End Sub
  • Print Button Code
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2. Dim g As Graphics = Me.CreateGraphics()
    3. Dim s As Size = Me.Size
    4. formImage = New Bitmap(s.Width, s.Height, g)
    5. Dim mg As Graphics = Graphics.FromImage(formImage)
    6. Dim dc1 As IntPtr = g.GetHdc
    7. Dim dc2 As IntPtr = mg.GetHdc
    8. Dim widthDiff As Integer = (Me.Width - Me.ClientRectangle.Width)
    9. Dim heightDiff As Integer = (Me.Height - Me.ClientRectangle.Height)
    10. Dim borderSize As Integer = widthDiff \ 2
    11. Dim heightTitleBar As Integer = heightDiff - borderSize
    12. BitBlt(dc2, 0, 0, Me.ClientRectangle.Width + widthDiff, Me.ClientRectangle.Height _
    13. + heightDiff, dc1, 0 - borderSize, 0 - heightTitleBar, 13369376)
    14. g.ReleaseHdc(dc1)
    15. mg.ReleaseHdc(dc2)
    16. pd.Print()End Sub
  • Then, Add this Following Declarations.
    1. Private WithEvents pd As Printing.PrintDocument
    2. Dim formImage As Bitmap
    3. Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" _
    4. (ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
    5. ByVal nYDest As Integer, ByVal nWidth As Integer, _
    6. ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, _
    7. ByVal nYSrc As Integer, ByVal dwRop As System.Int32) As Long
  • After that, Add This Following Sub.
    1. Private Sub pd_PrintPage(ByVal sender As Object, _
    2. ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage
    3. e.Graphics.DrawImage(formImage, 100, 100)
    4. End Sub
  • Finally, Add the Following to the Form Load Event.
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2. pd = New Printing.PrintDocument
    3. Me.StartPosition = FormStartPosition.CenterScreenEnd Sub
  • 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:

 

 

 

Facebook Comments
(Visited 88 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here