如题:
给出代码更好。
给出代码更好。
解决方案 »
- 连接Sql数据库提示:未能用指定连接串 "连接字段"连接到数据源,连接串中的用户名和密码已隐藏
- 发布问题
- [WinForm]AxWebBrowser浏览网页,怎么获取网页中图片的属性
- 动态创建数组问题
- [开始]菜单中的拖放如何完成的?
- 在C#.NET中如何将在 DataGrid (Winform下的) 双击过的行变为某个指定的颜色? -- 求助DataGrid高手们(急)
- C#中的dataGridView1实现上一条,下一条,首记录,尾记录 总是有些小问题,请高手帮忙
- C#中三级联动出现的问题
- 一个困扰我很久的问题,谢谢大家了!!!!!来帮我一下!!
- 请问c#做的程序怎样才能很好的释放资源?
- 我就剩35分了!【菜鸟问题、大家救急】一道老题儿!向数据库中插入记录的问题!
- 跪求:中英版网站web.config问题~~
private Font printFont;
private StreamReader streamToPrint;
// 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;
}