将发票打印为实时发票

将发票打印为实时发票

本文介绍了将发票打印为实时发票,而不仅仅是表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用vb.net和datagrid view在vb.net中设计了一个发票软件.如果要打印,请仅打印表格部分,打印后可以帮助您生成发票吗?
任何帮助将不胜感激
代码如下

I have designed an invoice software in vb.net by using vb.net and datagrid view.................but i am not able to print it like a good invoice should b printed,,only the form portion is being printed,,can you help to produce an invoice after printing it.
Any help will be appreciated
The code is as follows

Imports System.Data.SqlClient
Imports System
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Windows.Forms
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private WithEvents printButton As System.Windows.Forms.Button

    Private printFont As Font
    Private streamToPrint As StreamReader
    Dim connetionString As String
    Public Sub New()
        '' The Windows Forms Designer requires the following call.
        InitializeComponent()
        InitializeForm()
    End Sub
    Private Sub InitializeForm()
        Me.components = New System.ComponentModel.Container()
        Me.Button2 = New System.Windows.Forms.Button()

        Me.ClientSize = New System.Drawing.Size(800, 600)
        Me.Text = "Print Example"

        Button2.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Button2.Location = New System.Drawing.Point(12, 612)
        Button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Button2.TabIndex = 0
        Button2.Text = "Print the file."
        Button2.Size = New System.Drawing.Size(139, 23)
        AddHandler Button2.Click, AddressOf Button2_Click

        Me.Controls.Add(Button2)
    End Sub

    '' The PrintPage event is raised for each page to be printed.
    Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
        Dim linesPerPage As Single = 0
        Dim yPos As Single = 0
        Dim count As Integer = 0
        Dim leftMargin As Single = ev.MarginBounds.Left
        Dim topMargin As Single = ev.MarginBounds.Top
        Dim line As String = Nothing

        '' Calculate the number of lines per page.
        linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)

        '' Print each line of the file.
        While count < linesPerPage
            line = streamToPrint.ReadLine()
            If line Is Nothing Then
                Exit While
            End If
            yPos = topMargin + count * printFont.GetHeight(ev.Graphics)
            ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
            count += 1
        End While

        '' If more lines exist, print another page.
        If (line IsNot Nothing) Then
            ev.HasMorePages = True
        Else
            ev.HasMorePages = False
        End If
    End Sub









            Dim reply As DialogResult = MessageBox.Show("Do You want to print the Final Invoice", "Want the final Invoice Now !!", _
                  MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)
            If reply = Windows.Forms.DialogResult.Yes Then
                PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
                PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
                Button1.Visible = True
            End If

        End If

        Me.PageSetupDialog1 = New System.Windows.Forms.PageSetupDialog

        Me.SuspendLayout()




    End Sub



    End Sub





    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            streamToPrint = New StreamReader("C:\MyFile.txt")
            Try
                printFont = New Font("Arial", 10)
                Dim pd As New PrintDocument()
                AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
                pd.Print()
            Finally
                streamToPrint.Close()

    Public Shared Sub Main()
        Application.Run(New Form1())
    End Sub
End Class



内联代码转换为代码块-OriginalGriff [/edit]



[edit]Inline code converted to Code block - OriginalGriff[/edit]

推荐答案



这篇关于将发票打印为实时发票,而不仅仅是表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 09:47