本文实例讲述了C#打印绘图的实现方法。分享给大家供大家参考。具体实现方法如下:
string test = "";
public string Test
{
get { return test; }
set { test = value; }
}
public Form1()
{
InitializeComponent();
//设置纸张大小
PaperSize paperSize = new PaperSize("DataOrder", 1023, 614);
printDocument1.DefaultPageSettings.PaperSize = paperSize;
}
//打印
private void button1_Click(object sender, EventArgs e)
{
printDocument1.PrintPage += new PrintPageEventHandler(MyPrintDoc_PrintPage);
try
{
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.FormBorderStyle = FormBorderStyle.Fixed3D;
printPreviewDialog1.ShowDialog();
printDocument1.Print();
}
catch
{
MessageBox.Show("请安装打印机", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
protected void MyPrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
//字体 颜色 格式 坐标
drawFont = new Font("Arial", 8);
drawBrush = new SolidBrush(Color.Black);
x = 0F;
y = 0F;
drawFormat.FormatFlags = StringFormatFlags.NoWrap;
//块数
int num = 6;
float weightAll = 12.600F;
//标题
//标题第一行
string src="/uploads/allimg/150125/12463344G-0.jpg?2015020103929" style="border: 1px solid rgb(204, 204, 204); padding: 3px; max-width: 620px; overflow: hidden;" />
希望本文所述对大家的C#程序设计有所帮助。
新闻热点
疑难解答