private void Form2_Load(object sender, EventArgs e)
{
System.Drawing.Printing.PrintDocument _Documnet = new System.Drawing.Printing.PrintDocument();
_Documnet.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(_Documnet_PrintPage);
_Documnet.Print();
} void _Documnet_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString(textBox1.Text, textBox1.Font, new SolidBrush(textBox1.ForeColor), 100, 100);
}这样 100,100 你想定义到那都行
{
System.Drawing.Printing.PrintDocument _Documnet = new System.Drawing.Printing.PrintDocument();
_Documnet.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(_Documnet_PrintPage);
_Documnet.Print();
} void _Documnet_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString(textBox1.Text, textBox1.Font, new SolidBrush(textBox1.ForeColor), 100, 100);
}这样 100,100 你想定义到那都行
解决方案 »
- 一道算法题!高手请进
- TabControl重写问题,如何默认添加为重写后的MyTabPage
- 如何判断2个集合中的值?
- C#如何通过Collection中的元素得到拥有Collection的对象
- c#调用ORACLE过程的问题
- C#语法问题
- 知道两个DateTime.Now的时间,怎么求出他们的相差天数??
- 求助,如何通过刷卡机实现刷卡自动获取卡片物理地址
- System.NullReferenceException: 未将对象引用设置到对象的实例。
- 谁知道VS.NET中文版的CD-KEY?
- 怎样才能在类的开头添加"namespace MB.TheBeerHouse.******"(自定义)?
- 水晶报表 显示不数据
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 PrintTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} PrintDocument objDocument;
DialogResult resultP;
FontDialog f = new FontDialog();
ColorDialog color = new ColorDialog(); private void button1_Click(object sender, EventArgs e)
{
//初始化打印机设置窗口
PrintDialog priD = new PrintDialog();
//设置当前页按钮为真
priD.AllowCurrentPage = true;
//是否显示帮助按钮
priD.ShowHelp = true;
//是否启用打印到文件按钮
priD.AllowPrintToFile = true;
//是否启用选择按钮
priD.AllowSelection = true;
//是否启用页选项按钮
priD.AllowSomePages = true;
resultP = priD.ShowDialog();
if (resultP == DialogResult.OK)
{
object[] obj = new object[]
{
//获取打印机是否支持双面打印
priD.PrinterSettings.CanDuplex,
//打印文档是否逐份打印
priD.PrinterSettings.Collate,
//获取打印机允许用户打印的最大份数
priD.PrinterSettings.MaximumCopies,
//获取打印文档的份数
priD.PrinterSettings.Copies,
//获取此打印机默认页设置
priD.PrinterSettings.DefaultPageSettings,
//获取双面打印的打印机设置
priD.PrinterSettings.Duplex,
//获取打印第一页的页码
priD.PrinterSettings.FromPage,
//获取该打印机支持的纸张大小
priD.PrinterSettings.PaperSizes,
//获取用户已指定要打印的页码
priD.PrinterSettings.PrintRange,
//获取要打印最后一页的页码
priD.PrinterSettings.ToPage
};
listBox1.Items.AddRange(obj);
} //初始化要显示的设置窗口
PageSetupDialog objPageSetupDialog = new PageSetupDialog();
objPageSetupDialog.PageSettings = new PageSettings();
objPageSetupDialog.ShowNetwork = false;
//获取文档
objPageSetupDialog.Document = this.objDocument;
//显示窗口
//objPageSetupDialog.ShowDialog();
resultP = objPageSetupDialog.ShowDialog();
if (resultP == DialogResult.OK)
{
object[] resultsP = new object[]{
//获取该页的边距
objPageSetupDialog.PageSettings.Margins,
//获取该页纸张的大小
objPageSetupDialog.PageSettings.PaperSize,
//获取是横向还是纵向打印True为横向
objPageSetupDialog.PageSettings.Landscape,
};
listBox1.Items.AddRange(resultsP);
} //初始化要预览窗口
PrintPreviewDialog ppvw = new PrintPreviewDialog();
//获取要预览的文档
ppvw.Document = objDocument;
ppvw.Width = 800;
ppvw.Height = 600;
//显示预览窗口
ppvw.ShowDialog();
} private void Form1_Load(object sender, EventArgs e)
{
objDocument = new PrintDocument();
//当需要为当前页打印的输出时发生
objDocument.PrintPage += new PrintPageEventHandler(objDocument_PrintPage);
} void objDocument_PrintPage(object sender, PrintPageEventArgs e)
{
string objString = this.textBox1.Text;
//获取用于绘制页面的Graphics的对象
Graphics g = e.Graphics;
//向页面输出一行文字
g.DrawString(objString, f.Font, new SolidBrush(color.Color), new RectangleF(0, 200, textBox1.Width, textBox1.Height));
g.DrawString(objString, f.Font, new SolidBrush(f.Color), new PointF(30,30));
//画一个矩形框
g.DrawRectangle(new Pen(color.Color,2),200,200,200,200);
//打印一张图
Rectangle destRect = new Rectangle(450, 300, temp.Width,temp.Height);
g.DrawImage(temp, destRect, 0, 0, temp.Width, temp.Height, System.Drawing.GraphicsUnit.Pixel);
} private void btncolor_Click(object sender, EventArgs e)
{
resultP = color.ShowDialog();
if (resultP == DialogResult.OK)
{
object[] obj1 = new object[]
{
color.Color
};
listBox1.Items.AddRange(obj1);
}
} private void btnFont_Click(object sender, EventArgs e)
{
//对话框中是否显示颜色选择
f.ShowColor = true;
resultP = f.ShowDialog();
if (resultP == DialogResult.OK)
{
object[] obj2 = new object[]
{
f.Font,
f.ShowColor
};
listBox1.Items.AddRange(obj2);
}
}
}
}
Image temp = Image.FromFile(@"D:\网络.png");绝对路径,自己可以改