当前注册人数422991人 邮箱: 密码: 注册新用户 忘记密码
首页 C/C++/MFC C# ASP.NET VB.NET MATLAB Android   站内搜索 下载代码说明/积分规则
为什么要注册?

1. 可以直接免费从本站下载代码,防止邮件发送不到您的邮箱,或登录不了国外网站

2. 可以设定关键字,当有您关心的代码收录时,邮件通知您

3. 对这里的代码进行评分和评论

4. 可以和大家一起分享你的源代码,得到更多的建议

Basic Text and Image Printing

VB.NET中最基础的文本和图像打印示例教程及源代码

2008年02月25日
VB, Windows, .NET, WinXP, .NET 2.0, VS, VS2005, Dev
这个文章一步一步的教你如何使用Print Document, Print Dialog, Print Preview 和 Page Setup控件,实现打印最基本的文本和图像。涉及打印文档、打印对话框、打印预览及打印机页面设置。程序运行于.NET 2.0下,实现语言是VB.NET。
相关知识
Private Sub PrintTextControl_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs)_
Handles PrintTextControl.PrintPage

  PrintTextControl.DocumentName = "Test Document"

  Dim PrintFont As New Font(TextToPrint.Font, TextToPrint.Font.Style)
  Dim numChars As Integer
  Dim numLines As Integer
  Dim stringForPage As String
  Dim strFormat As New StringFormat

  Dim rectDraw As New RectangleF(e.MarginBounds.Left, _
    e.MarginBounds.Top, e.MarginBounds.Width, e.MarginBounds.Height)

    'Determine maximum text ammount and spaces lines

    Dim sizeMeasure As New SizeF(e.MarginBounds.Width, _
        e.MarginBounds.Height - PrintFont.GetHeight(e.Graphics))

    'Break in between words

     strFormat.Trimming = StringTrimming.Word

     'Determines ammount of words and lines that can fit on a page

     e.Graphics.MeasureString(PrintString, PrintFont, sizeMeasure, _
        strFormat, numChars, numLines)
 
    stringForPage = PrintString.Substring(0, numChars)

    'Print strings to page

    e.Graphics.DrawString(stringForPage, PrintFont, Brushes.Black, rectDraw, strFormat)

    'Determine whether or not there are more pages to print

    If numChars < PrintString.Length Then
      'Remove printed text from string

      PrintString = PrintString.Substring(numChars)
      e.HasMorePages = True
    Else
      e.HasMorePages = False

      'Restore string after printing

      PrintString = TextToPrint.Text
    End If
End Sub
源代码原文下载:
Basic Text and Image Printing This article will teach you the basics of printing text and graphics with the Print Document, Print Dialog, Print Preview and Page Setup controls.

源码图片

点击链接查看大图
从本站下载附件及源代码(1个附件,已经成功下载644次)

最值得关注的外文源代码

Calculator
A ReportPrinting Framework on Mike Mayer's ReportPrinting core library
Gridview Control with print and preview features
Easy Inline Text Editor 2.0
评论(评论是增加积分的一个有效途径)
字数在300字内
请如实评论
本源代码共评论74次,此处显示最近20次评论! 查看所有评论

没说不算话  2017年01月23日
为什么要2天?急需怎么弄?
65041078  2016年08月19日
谢谢分享
yinggood  2016年03月24日
很好,综合自己的东西一下
nick111  2015年01月12日
hao ,zn me xia zai a
bingxin20140823  2014年10月31日
xiexie
hxkcyjs  2014年09月28日
太好了,谢谢分享
MXT_GIVEMEFIVE  2014年05月24日
谢谢分享
whl20092183  2013年10月31日
强大
qqqqq  2013年05月14日
学习学习
feifei  2013年04月24日
太好了
zjl138  2013年02月22日
学习了,正需要
wuliao  2013年01月16日
学习学习
hxkcyjs  2012年12月07日
正是我需要的,谢谢
秋风夕雨  2012年10月03日
学习!
雷少敏  2012年09月21日
谢谢分享,学习中。。。
hxkcyjs  2012年08月08日
很好,谢谢
superdragondcl  2012年06月27日
学习中,谢谢!
mustvvv  2012年04月09日
下了 ,谢谢
saaf  2012年01月25日
不错.
jdtx2011  2012年01月07日
不错
字数在300字内
请如实评论
200万国内源码搜索
CopyRight (C) codesoso.com 2007-2009 All Rights Reserved zhihuishi   免责声明