• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
nicesoft
博客园    首页    新随笔    联系   管理    订阅  订阅

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

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

 

posted @ 2011-02-01 21:26  nicesoft  阅读(550)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3