关于datagrid的打印
点击次数:43 次 发布日期:2008-11-06 08:08:10 作者:源代码网
|
源代码网推荐using System.Windows.Forms; 源代码网推荐using System.Drawing; 源代码网推荐using System.Drawing.Printing; 源代码网推荐using System.Data; 源代码网推荐using System.Collections; 源代码网推荐 源代码网推荐namespace Sx_Mdi 源代码网推荐{ 源代码网推荐/// <summary> 源代码网推荐/// Summary description for DataGridPrinter. 源代码网推荐/// </summary> 源代码网推荐public class DataGridPrinter 源代码网推荐{ 源代码网推荐 源代码网推荐private PrintDocument ThePrintDocument; 源代码网推荐private DataTable TheTable; 源代码网推荐private DataGrid TheDataGrid; 源代码网推荐 源代码网推荐public int RowCount = 0; // current count of rows; 源代码网推荐private const int kVerticalCellLeeway = 10; 源代码网推荐public int PageNumber = 1; 源代码网推荐 源代码网推荐int PageWidth; 源代码网推荐int PageHeight; 源代码网推荐int TopMargin; 源代码网推荐int BottomMargin; 源代码网推荐 源代码网推荐public string receieve_amount; //收货数量 源代码网推荐public string receieve_moneys; //收货金额 源代码网推荐public string send_amount; //发货数量 源代码网推荐public string send_moneys; //发货金额 源代码网推荐 源代码网推荐 源代码网推荐public DataGridPrinter(DataGrid aGrid, PrintDocument aPrintDocument, DataTable aTable) 源代码网推荐{ 源代码网推荐// 源代码网推荐// TODO: Add constructor logic here 源代码网推荐// 源代码网推荐TheDataGrid = aGrid; 源代码网推荐ThePrintDocument = aPrintDocument; 源代码网推荐TheTable = aTable; 源代码网推荐 源代码网推荐 源代码网推荐//得到打印参数 源代码网推荐PageWidth = ThePrintDocument.DefaultPageSettings.PaperSize.Width; 源代码网推荐PageHeight = ThePrintDocument.DefaultPageSettings.PaperSize.Height; 源代码网推荐TopMargin = ThePrintDocument.DefaultPageSettings.Margins.Top; 源代码网推荐BottomMargin = ThePrintDocument.DefaultPageSettings.Margins.Bottom; 源代码网推荐 源代码网推荐} 源代码网推荐 源代码网推荐public void GetValues(string sh_amount,string sh_moneys,string fh_amount,string fh_moneys) 源代码网推荐{ 源代码网推荐// 源代码网推荐// TODO: Add constructor logic here 源代码网推荐// 源代码网推荐receieve_amount = sh_amount; 源代码网推荐receieve_moneys = sh_moneys; 源代码网推荐send_amount = fh_amount; 源代码网推荐send_moneys = fh_moneys; 源代码网推荐 源代码网推荐 源代码网推荐} 源代码网推荐 源代码网推荐public void DrawHeader(Graphics g) 源代码网推荐{ 源代码网推荐SolidBrush ForeBrush = new SolidBrush(TheDataGrid.HeaderForeColor); 源代码网推荐SolidBrush BackBrush = new SolidBrush(TheDataGrid.HeaderBackColor); 源代码网推荐Pen TheLinePen = new Pen(TheDataGrid.GridLineColor, 1); 源代码网推荐StringFormat cellformat = new StringFormat(); 源代码网推荐cellformat.Trimming = StringTrimming.EllipsisCharacter; 源代码网推荐cellformat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit; 源代码网推荐 源代码网推荐 源代码网推荐g.DrawString("收发对比表",new Font("Arial", 20, FontStyle.Bold), new SolidBrush(TheDataGrid.HeaderBackColor), PageWidth/2 , TopMargin, new StringFormat()); 源代码网推荐 源代码网推荐int columnwidth = PageWidth/TheTable.Columns.Count - 20; 源代码网推荐 源代码网推荐 源代码网推荐int initialRowCount = RowCount; 源代码网推荐 源代码网推荐// draw the table header 源代码网推荐float startxposition = TheDataGrid.Location.X; 源代码网推荐RectangleF nextcellbounds = new RectangleF(0,0, 0, 0); 源代码网推荐 源代码网推荐RectangleF HeaderBounds = new RectangleF(0, 0, 0, 0); 源代码网推荐 源代码网推荐HeaderBounds.X = TheDataGrid.Location.X; 源代码网推荐HeaderBounds.Y = TheDataGrid.Location.Y TopMargin (RowCount - initialRowCount) * (TheDataGrid.Font.SizeInPoints kVerticalCellLeeway); 源代码网推荐HeaderBounds.Height = TheDataGrid.Font.SizeInPoints kVerticalCellLeeway; 源代码网推荐 源代码网供稿. |
