关于打印(Winform)?

chinadragon5188 2006-07-03 06:11:33
C#,怎么实现呀,感觉特迷惑。
...全文
249 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
www.webmis.com.cn源码

www.AnyReport.Net套打
cscer 2006-07-10
  • 打赏
  • 举报
回复
主要看你需要实现什么样的打印操作
huacha 2006-07-10
  • 打赏
  • 举报
回复
http://www.wave12.com/web/SigCon.asp?bCate=50&sCateName=%B9%A6%C4%DC%BD%E9%C9%DC&ID=173&CateName=wsReport4.6
chinadragon5188 2006-07-04
  • 打赏
  • 举报
回复
水晶报表是否更好一些呢?
Firestone2003 2006-07-03
  • 打赏
  • 举报
回复
Windows 窗体 PrintDocument 组件用于设置一些属性,这些属性说明在基于 Windows 的应用程序中要打印什么内容以及打印文档的能力。可将它与 PrintDialog 组件一起使用来控制文档打印的各个方面。

使用 PrintDocument 组件
涉及 PrintDocument 组件的两种主要情况是:

简单的打印作业,如打印单个文本文件。在这种情况下,应将 PrintDocument 组件添加到 Windows 窗体,然后在 PrintPage 事件处理程序中添加打印文件的编程逻辑。该编程逻辑应以使用 Print 方法打印文档结束。此方法向打印机发送一个 Graphics 对象,该对象包含在 PrintPageEventArgs 类的 Graphics 属性中。

更为复杂的打印作业,如想要重新使用已编写的打印逻辑的情况。在这种情况下,应从 PrintDocument 组件派生一个新组件,并重写(参见 Visual Basic 的 重写 或 C# 的 重写)PrintPage 事件。

将 PrintDocument 组件添加到窗体后,它出现在 Windows 窗体设计器底部的栏中。

Visual Studio 中对此功能提供了广泛的支持。有关更多信息,请参见 PrintDocument 组件(Windows 窗体)。
public class PrintingExample : System.Windows.Forms.Form
{
private System.ComponentModel.Container components;
private System.Windows.Forms.Button printButton;
private Font printFont;
private StreamReader streamToPrint;

public PrintingExample() : base()
{
// The Windows Forms Designer requires the following call.
InitializeComponent();
}

// The Click event is raised when the user clicks the Print button.
private void printButton_Click(object sender, EventArgs e)
{
try
{
streamToPrint = new StreamReader
("C:\\My Documents\\MyFile.txt");
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler
(this.pd_PrintPage);
pd.Print();
}
finally
{
streamToPrint.Close();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;

// 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()) != null))
{
yPos = topMargin + (count *
printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}

// If more lines exist, print another page.
if(line != null)
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}


// The Windows Forms Designer requires the following procedure.
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.printButton = new System.Windows.Forms.Button();

this.ClientSize = new System.Drawing.Size(504, 381);
this.Text = "Print Example";

printButton.ImageAlign =
System.Drawing.ContentAlignment.MiddleLeft;
printButton.Location = new System.Drawing.Point(32, 110);
printButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
printButton.TabIndex = 0;
printButton.Text = "Print the file.";
printButton.Size = new System.Drawing.Size(136, 40);
printButton.Click += new System.EventHandler(printButton_Click);

this.Controls.Add(printButton);
}

// This is the main entry point for the application.
public static void Main(string[] args)
{
Application.Run(new PrintingExample());
}
}

111,118

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧