要求:可设置纸型(如:A4,A3,B4,B5),和自定义纸型。
重点在于自定义纸型,打印机不在默认纸型下,可打印代码设置的纸型。
如果已知打印纸型的长和宽,如何打印?用什么控件要写明白。
请多写注释!关于打印的类,偶实在是迷糊的很。
由于偶从来没学过打印,特请各位大虾帮忙。
重点在于自定义纸型,打印机不在默认纸型下,可打印代码设置的纸型。
如果已知打印纸型的长和宽,如何打印?用什么控件要写明白。
请多写注释!关于打印的类,偶实在是迷糊的很。
由于偶从来没学过打印,特请各位大虾帮忙。
解决方案 »
- 关于点绕点旋转
- int与intptr转换问题
- monthcalendar在win7和xp下外观不一样,是framework的原因吗
- button或者linkbutton按钮加删除确认功能
- 关于C# GDI+重绘的问题
- C#关于窗口关闭操作
- 如何在页面上原样显示一个XML格式的字符串
- C#写从log文件向access自动导入数据的窗口程序,运行一段时间后停止工作,问题事件名称:CLR20r3,求教各位该怎么解决?谢谢
- 如何让VC#作的程序在没有安装.net框架上的机器上运行?
- 有没有什么办法可以传递“方法”?
- msi卸载出错
- 求急!!!如何在vs中的DataGridview中显示用SQL语句查到的内容?
http://blog.csdn.net/cnming/archive/2008/03/22/2204496.aspx
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
using System.Data;
using System.Text;
namespace PrintText.Method
{
class Print
{
private static StringFormat StrFormat;
private static StringFormat StrFormatComboBox;
private static string PrintTitle = "";
private static System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument(); private static TextBox textBox1;
private static TextBox textBox2;
private static Label label1;
private static Label label2;
public static void Pint_test(Panel Pane)
{
PrintPreviewDialog textPint;
try
{
label1 = (Label)Pane.Controls.Find("label1", true)[0];
textBox1 = (TextBox)Pane.Controls.Find("textBox1", true)[0];//姓名 label2 = (Label)Pane.Controls.Find("label2", true)[0];
textBox2 = (TextBox)Pane.Controls.Find("textBox2", true)[0];//性别 textPint = new PrintPreviewDialog();
textPint.Document = printDoc;
printDoc.BeginPrint += new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
if (textPint.ShowDialog() != DialogResult.OK)
{
printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
return;
}
printDoc.Print();
printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{ } } private static void PrintDoc_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
try
{
StrFormat = new StringFormat();
StrFormat.Alignment = StringAlignment.Near;//布局对齐
StrFormat.LineAlignment = StringAlignment.Center;//居中对齐
StrFormat.Trimming = StringTrimming.EllipsisCharacter;//指定如何在不完全适合布局形状的字符串中修整字符
StrFormatComboBox = new StringFormat();
StrFormatComboBox.LineAlignment = StringAlignment.Center;
StrFormatComboBox.FormatFlags = StringFormatFlags.NoWrap;
StrFormatComboBox.Trimming = StringTrimming.EllipsisCharacter; }
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} private static void PrintDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{ //姓名
e.Graphics.DrawRectangle(Pens.Black, 60, 100, 700, 200);
String A = "姓名";
e.Graphics.DrawString(A, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 120, 120); e.Graphics.DrawRectangle(Pens.Black, 60, 100, 150, 40);
String B = "";
e.Graphics.DrawString(B, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 60, 150); e.Graphics.DrawRectangle(Pens.Black, 60, 140, 150, 40);
String C = textBox1.Text;
e.Graphics.DrawString(C, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 100, 150); e.Graphics.DrawRectangle(Pens.Black, 60, 180, 150, 40);
String D = "";
e.Graphics.DrawString(D, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 60, 150);
e.Graphics.DrawRectangle(Pens.Black, 60, 220, 150, 40);
String E = "";
e.Graphics.DrawString(E, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 60, 150);
e.Graphics.DrawRectangle(Pens.Black, 60, 260, 150, 40);
String F = "";
e.Graphics.DrawString(F, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 60, 150);
}
}
}
private void initDialog()
{
//新建打印页面
printDocument = new PrintDocument(); //初始化标题格式
titleFormat = new StringFormat();
titleFormat.Alignment = StringAlignment.Center;
titleFormat.LineAlignment = StringAlignment.Center;
titleFormat.Trimming = StringTrimming.EllipsisCharacter; //初始化数据区格式
dataFormat = new StringFormat();
dataFormat.Alignment = StringAlignment.Center;
dataFormat.LineAlignment = StringAlignment.Far;
dataFormat.Trimming = StringTrimming.EllipsisCharacter; //设置页面格式
pageSetupDialog = new PageSetupDialog();
pageSetupDialog.AllowOrientation = true; //允许横向
pageSetupDialog.Document = printDocument; //绑定页面
if (this.title.IndexOf(CommonString.strAlTableKey) > 0)
{
pageSetupDialog.Document.DefaultPageSettings.Landscape = false; //设置打印为纵向; normalFont = new Font("NSimSun", 9);
sumFont = new Font("NSimSun", 9);
}
else
{
pageSetupDialog.Document.DefaultPageSettings.Landscape = true; //设置打印为横向
pageSetupDialog.PageSettings.Margins.Left = 20;
pageSetupDialog.PageSettings.Margins.Top = 50;
normalFont = new Font("NSimSun", 6);
sumFont = new Font("NSimSun", 6);
} printPreviewDialog = new PrintPreviewDialog();
printPreviewDialog.Document = printDocument;
printPreviewDialog.Height = 600;
printPreviewDialog.Width = 800;
printPreviewDialog.ClientSize = new System.Drawing.Size(1500, 1000); //纸张1169, 827
printPreviewDialog.PrintPreviewControl.Zoom = 1; //初始页
curPage = 1;
//初始打印行
RowPos = 0;
if(this.dgv.Rows.Count < 10)
{
rowGap = rowGap * 3 / 2;
sumRowGap = sumRowGap * 3 / 2;
} //初始化列宽度
initColHeightInfo(0);
}看看是否有帮助吧
你结合自己的情况,其中pageSetupDialog.ShowDialog();可以看到都可以设置什么,自己再研究下就OK了
private PageSetupDialog pageSetupDialog;
private PrintPreviewDialog printPreviewDialog;
你要设置的东西我想只能在PageSetupDialog 中设定了
是实例化以后在设置吗 ?
这个对象的哪些属性是设置纸型的?