对于文本文件的打印例子见过了不少,但对于图形的打印,还从来没有用过,也找不到例子程序,故有如下问题请教大家!
1、关于文件夹中的.gif、.jpg、.bmp图形如何打印?
2、关于数据库中的二进制文件如何打印?请各位高手教教我吧。能有个现成的实例程序,千万别忘了发一个给我,谢谢大家啦!!
[email protected]
拜托!!
1、关于文件夹中的.gif、.jpg、.bmp图形如何打印?
2、关于数据库中的二进制文件如何打印?请各位高手教教我吧。能有个现成的实例程序,千万别忘了发一个给我,谢谢大家啦!!
[email protected]
拜托!!
解决方案 »
- 这段代码描述我最近的心情
- 求解 Reflector 反编译 dll文件过程
- 一个关于循环的小问题
- 提个关于水晶报表的最最简单问题,如何绑定TextBox?
- 有谁用过Enterprise Library1.0 -- DataAccess Application Block 没
- 为什么.net语法错误!!!
- 请教如何在C#中调用VC开发的ActiveX控件的方法
- 在winForm的程序里,如何在datagrid中插入comobox?
- 确认一下,用VS2003开发的软件,可以在哪些操作系统下运行了?
- 如何在一个datagrid中显示两个dataset
- 请问如何设定精度(小数点后面的位数)?
- textBox.text的内容要以word文件方式输出,该怎么做
{
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.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
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());
}
}