您的位置:首页 > 编程语言 > C#

简单代码打印出不断长大的文字[C#]

2011-02-01 21:26 615 查看
C#中,打印不断长大的文字

代码

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
);
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: