C# 打印机如何设置比例打印(放大/缩小) 5
1个回答
展开全部
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);
}
}
}
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);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询