本文實例講述了C#打印繪圖的實現(xiàn)方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
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;
//塊數(shù)
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#程序設計有所幫助。
新聞熱點
疑難解答