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
);
}
}
}
}