将发票打印为实时发票,而不仅仅是表格

编程入门 行业动态 更新时间:2024-10-26 06:37:09
本文介绍了将发票打印为实时发票,而不仅仅是表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have designed an invoice software in vb by using vb 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() Meponents = 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]

推荐答案

不要那样做. PrintForm可以-ish-,但是您确实想正确地完成这项工作.使用 PrintDocument [ ^ ]-它提供了更好的服务控制,以及看起来更好地作为打印对象.该链接包含一个示例. Don''t do it that way. PrintForm is ok -ish- but you really want to do the job properly. Use a PrintDocument[^] instead - it provides a lot better control, and well as looking better as a printed object. The link includes an example.

u应该使用水晶报表.... u should use crystal reports ....

更多推荐

将发票打印为实时发票,而不仅仅是表格

本文发布于:2023-11-23 02:12:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619714.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发票   而不   仅仅是   实时   表格

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!