C#打印绘图的实现方法

2019-12-26 12:17:38王旭
易采站长站为您分析C#打印绘图的实现方法,涉及C#针对图片的绘制与打印相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下    

本文实例讲述了C#打印绘图的实现方法。。具体实现方法如下:

 

复制代码
String drawString = "";
Font drawFont = null;
SolidBrush drawBrush = null;
float x = 0F;
float y = 0F;
StringFormat drawFormat = new StringFormat();

 

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="https://www.easck.com/d/file/150125/12463344G-0.jpg?2015020103929" style="border: 1px solid rgb(204, 204, 204); padding: 3px; max-width: 620px; overflow: hidden;" />