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

本文介绍了一个使用 C# 实现的简单示例,该示例可以在打印页面上生成逐渐变化字体大小的文字。通过调整字体大小并测量每一行的实际高度来确保每行文字都能正确打印,并且每行之间的间距也会根据字体大小的变化而变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C#中,打印不断长大的文字

2011020121245470.jpg

 

ContractedBlock.gifExpandedBlockStart.gif代码
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
);
}
}
}
}

 

转载于:https://www.cnblogs.com/190196539/archive/2011/02/01/1948782.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值