简单代码打印出不断长大的文字[C#]
时间:2011-02-01 来源:nicesoft
代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
namespace PrintTest3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
//设置边距
//Margins margin = new Margins(20, 20, 20, 20);
//pd.DefaultPageSettings.Margins=margin;
pd.PrintPage += pd_PrintPage;
pd.Print();
}
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
for (int i = 0; i < 10; i++)
{
//动态获取字符的高度
SizeF string_size = e.Graphics.MeasureString("第{0}行", new Font("宋体", 12+i));
e.Graphics.DrawString
(
string.Format("第{0}行", i), new Font("宋体", 12 + i),
Brushes.Black, 100, 100 + string_size.Height*i
);
}
}
}
}
相关阅读 更多 +