C#列印繪圖的實現方法

來源:互聯網
上載者:User

標籤:oar   splay   訂單號   監聽器   href   上傳   dbr   xxx   for   

本文執行個體講述了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 title = “鋼板入庫計量單”;

string BillCode = “吊號:” + “20080505170”;

string ClassType = “班別:” + “乙”;

string type1 = “類型:” + “定軋”;

string OrderNum = “記錄單號:” + “QW-Y14-02-06”;

//標題第二行

string ArriveStation = “到站:”;

string SpLine = “專用線:”;

string SaleNo = “銷售訂單號:”;

//標題第三行

string AcceptName = “收貨單位:” + “XXXX/12*2438*9144收二支”;

string time = DateTime.Now.Year.ToString() + “年” + DateTime.Now.Month.ToString().PadLeft(2,’0′)+”月”+DateTime.Now.Day.ToString()+”日”;

//表格下資料

string BoardNum = “合計:” + num.ToString() + ”    塊      ” + weightAll.ToString()+”   噸   “;

string CheckMan1 = “檢查員:” + “”;

string MeName = “計量員:”+”XX”;

string CheckMan2 = “核對員:” + “”;

//線條長度

Pen line = new Pen(drawBrush, 1);

//繪圖–字的位置

//繪圖–總標題

e.Graphics.DrawString(title, drawFont, drawBrush, 400, 45, drawFormat);

//繪圖–標題–第一行

//吊號

e.Graphics.DrawString(BillCode, drawFont, drawBrush, 125,83, drawFormat);

//班別

e.Graphics.DrawString(ClassType, drawFont, drawBrush, 354, 83, drawFormat);

//類型

e.Graphics.DrawString(type1, drawFont, drawBrush, 500, 83, drawFormat);

//記錄單號

e.Graphics.DrawString(OrderNum, drawFont, drawBrush, 685, 83, drawFormat);

//繪圖–標題–第二行

//到站

e.Graphics.DrawString(ArriveStation, drawFont, drawBrush, 125, 106, drawFormat);

//專用線

e.Graphics.DrawString(SpLine, drawFont, drawBrush, 354, 106, drawFormat);

//銷售訂單號

e.Graphics.DrawString(SaleNo, drawFont, drawBrush, 500, 106, drawFormat);

//繪圖–標題–第三行

//收貨單位

e.Graphics.DrawString(AcceptName, drawFont, drawBrush, 125, 129, drawFormat);

//時間

e.Graphics.DrawString(time, drawFont, drawBrush, 685, 129, drawFormat);


//繪圖–表格下資料

//合計

e.Graphics.DrawString(BoardNum, drawFont, drawBrush, 125, 568, drawFormat);

//檢查員

e.Graphics.DrawString(CheckMan1, drawFont, drawBrush, 400, 568, drawFormat);

//計量員

e.Graphics.DrawString(MeName, drawFont, drawBrush, 550, 568, drawFormat);

//核對員

e.Graphics.DrawString(CheckMan2, drawFont, drawBrush, 700, 568, drawFormat);

//繪圖 表格

float leftbianJu = 120;

float topbianJu = 152;

float tableWidth = 770;

float tableHeight = 393;

float cellwidth = 55;

float cellwidth1 = 110;

float cellheigh = 0F;

//繪圖–線的位置 外邊矩形

//橫

e.Graphics.DrawLine(line, leftbianJu, topbianJu,leftbianJu+tableWidth,topbianJu);

e.Graphics.DrawLine(line, leftbianJu, topbianJu + tableHeight, leftbianJu + tableWidth, topbianJu + tableHeight);

//豎

e.Graphics.DrawLine(line, leftbianJu, topbianJu, leftbianJu, topbianJu+tableHeight);

e.Graphics.DrawLine(line, leftbianJu + tableWidth, topbianJu, leftbianJu + tableWidth, topbianJu + tableHeight);

//e.Graphics.DrawLine(line, 15, 0, 15, 614);

//繪圖–內部豎線的位置

y = topbianJu+tableHeight;

x = leftbianJu + cellwidth;

e.Graphics.DrawLine(line, x, topbianJu, x,y );

x= leftbianJu + cellwidth + cellwidth1;

e.Graphics.DrawLine(line,x , topbianJu, x, y);

x = leftbianJu + cellwidth + cellwidth1 * 2;

e.Graphics.DrawLine(line, x, topbianJu, x, y);

x = leftbianJu + cellwidth + cellwidth1 * 3;

e.Graphics.DrawLine(line, x, topbianJu, x, y);

x = leftbianJu + cellwidth * 2 + cellwidth1 * 3;

e.Graphics.DrawLine(line, x, topbianJu, x, y);

x = leftbianJu + cellwidth * 3 + cellwidth1 * 3;

e.Graphics.DrawLine(line, x, topbianJu, x, y);

x = leftbianJu + cellwidth * 4 + cellwidth1 * 3;

e.Graphics.DrawLine(line, x, topbianJu, x, y);

x = leftbianJu + cellwidth * 5 + cellwidth1 * 3;

e.Graphics.DrawLine(line, x, topbianJu, x, y);

x = leftbianJu + cellwidth * 6 + cellwidth1 * 3;

e.Graphics.DrawLine(line, x, topbianJu, x, y);

x = leftbianJu + cellwidth * 7 + cellwidth1 * 3;

e.Graphics.DrawLine(line, x, topbianJu, x, y);

//繪圖–內部橫線的位置

//根據塊數計算表格高度

if (num != 0)

cellheigh = tableHeight / (float)num;

else

cellheigh = 0;

//繪圖–內部橫線的位置

for (int i = 1; i < num; i++)

{

if (i == 1)

{

//資料

string str = “”;

str = “序號”;

x = leftbianJu + cellwidth / 5;

y = topbianJu + cellheigh / 3;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

str = “卡片編號”;

x = leftbianJu + cellwidth + cellwidth1 / 5;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

str = “爐號”;

x = leftbianJu + cellwidth + cellwidth1 + cellwidth1 / 5;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

str = “物料編碼”;

x = leftbianJu + cellwidth + cellwidth1*2 + cellwidth1 / 5;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

str = “牌號”;

x = leftbianJu + cellwidth + cellwidth1*3 + cellwidth / 5;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

str = “厚度”;

x = leftbianJu + cellwidth * 2 + cellwidth1 * 3 + cellwidth / 5;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

str = “寬度”;

x = leftbianJu + cellwidth * 3 + cellwidth1 * 3 + cellwidth / 5;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

str = “長度”;

x = leftbianJu + cellwidth * 4 + cellwidth1 * 3 + cellwidth / 5;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

str = “重量”;

x = leftbianJu + cellwidth * 5 + cellwidth1 * 3 + cellwidth / 5;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

str = “層級”;

x = leftbianJu + cellwidth * 6 + cellwidth1 * 3 + cellwidth / 5;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

str = “偏差”;

x = leftbianJu + cellwidth * 7 + cellwidth1 * 3 + cellwidth / 5;

e.Graphics.DrawString(str, drawFont, drawBrush, x, y, drawFormat);

}

//橫線

y = topbianJu + cellheigh * i;

e.Graphics.DrawLine(line, leftbianJu, y, leftbianJu + tableWidth, y);

}

e.HasMorePages = false;

}

除聲明外, 跑步客文章均為原創,轉載請以連結形式標明本文地址
  C#列印繪圖的實現方法

本文地址:  http://www.paobuke.com/develop/c-develop/pbk23178.html






相關內容C#檔案上傳與下載的實現方法C#中反射和擴充方法如何運用C# 最齊全的上傳圖片方法淺析JAVA中過濾器、監聽器、攔截器的區別
C#中Socket通訊用法執行個體詳解C#基礎文法:Base關鍵字學習筆記Unity3D動態對象最佳化代碼分享C#中的委託、事件學習筆記

C#列印繪圖的實現方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.