C# 打印机如何设置比例打印(放大/缩小) 5

 我来答
pop_1982
推荐于2016-02-06 · TA获得超过142个赞
知道小有建树答主
回答量:456
采纳率:0%
帮助的人:228万
展开全部
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;
using System.Drawing.Drawing2D;

namespace WindowsApplication3
{
public partial class Form9 : Form
{
string filename = "myfile.txt";
Font printerfont = null;
public Form9()
{
InitializeComponent();
}

static Rectangle GetRealPageBounds(PrintPageEventArgs e, bool preview)
{
if (preview) return e.MarginBounds;

float cx = e.PageSettings.HardMarginX;
float cy = e.PageSettings.HardMarginY;

float dpix = e.Graphics.DpiX;
float dpiy = e.Graphics.DpiY;
Rectangle marginBounds = e.MarginBounds;
marginBounds.Offset((int)(-cx * 100 / dpix), (int)(-cy * 100 / dpiy));
return marginBounds;

}

private void button1_Click(object sender, EventArgs e)
{
this.printDocument1.DocumentName = this.filename;
this.pageSetupDialog1.Document = this.printDocument1;
this.pageSetupDialog1.ShowDialog();
this.printDialog1.Document = this.printDocument1;
if (this.printDialog1.ShowDialog() == DialogResult.OK)
{
this.printDocument1.Print();
}
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics g = e.Graphics;
bool preview = false;
RectangleF realMarginBounds = GetRealPageBounds(e, preview);
g.DrawString("Content", printerfont, Brushes.Red, realMarginBounds);
}

private void printDocument1_EndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
printerfont.Dispose();
printerfont = null;
}

private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
printerfont = new Font("Lucida Console", 72);
}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式