Calculating Services Provided and Discount - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

For this tutorial you need:

5 TextBoxes
8 Labels
4 Buttons

Calculating Services Provided and Discount- vb.net
Calculate Button Code:
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

Clear Button Code:
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

Exit Button Code:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles Button4.Click
     End
End Sub

Add The following declarations:

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
  
Add the following Sub
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
Then add the following Form Load Event
Private Sub Form1_Load(ByVal sender As Object, _
 ByVal e As System.EventArgs) Handles MyBase.Load
        pd = New Printing.PrintDocument
        Me.StartPosition = FormStartPosition.CenterScreen
End Sub
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
Download Source Code


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.