datagrid| print using System;
Using System.Windows.Forms;
Using System.Drawing;
Using System.Drawing.Printing;
Using System.Data;
Using System.Collections;
Using Datalibrary;
Namespace Controllibrary
{
<summary>
DataGrid printing
</summary>
public class Datagridprinter
{
Private PrintDocument Theprintdocument;
Private DataTable thetable;
Private DataGrid Thedatagrid;
public int rowcount = 0;
Private Const int kverticalcellleeway = 10;
public int pagenumber = 1;
Public ArrayList Lines = new ArrayList ();
public int header=0;
public int footer=0;
Datacatena DataCatena1;
public int pagewidth;
public int pageheight;
public int TopMargin;
public int bottommargin;
int gridwidth = 0;
public int LeftMargin;
public int RightMargin;
public string Papername;
public int PageCount;
private int rows_page;
public bool Showfooter;
public int Bodylength
{
Get
{
if (this. Pagenumber<this.pagecount)
Return (1+this.rows_page) * (int) (TheDataGrid.Font.SizeInPoints) + Kverticalcellleeway);
Else
Return (this. TheTable.Rows.Count + 1-(this.rows_page*) (this. PageNumber-1)) ((int) (TheDataGrid.Font.SizeInPoints) + Kverticalcellleeway);
}
}
Public Datagridprinter (DataGrid Agrid, PrintDocument aprintdocument,string theform,int Header,int)
{
//
Todo:add constructor Logic here
//
This.header=header;
This.footer=footer;
This.showfooter=true;
Thedatagrid = Agrid;
Theprintdocument = aprintdocument;
if (theform!= "")
{
Datacatena1=new Datacatena ();
DataView Mydv=datacatena1.getdataview ("select * from Yh_bbdy where bm= '" +theform + "");
public bool Drawrows (Graphics g)
{
int lastrowbottom = TopMargin;
Lines.clear ();
Try
{
SolidBrush Forebrush = new SolidBrush (Thedatagrid.forecolor);
SolidBrush Backbrush = new SolidBrush (Thedatagrid.backcolor);
SolidBrush Alternatingbackbrush = new SolidBrush (Thedatagrid.alternatingbackcolor);
Pen Thelinepen = new Pen (thedatagrid.gridlinecolor, 1);
StringFormat CellFormat = new StringFormat ();
CellFormat. trimming = Stringtrimming.ellipsischaracter;
CellFormat. FormatFlags = Stringformatflags.nowrap | Stringformatflags.linelimit;
int columnwidth = Pagewidth/thedatagrid.tablestyles[0]. Gridcolumnstyles.count;
int initialrowcount = (this. PAGENUMBER-1) *this.rows_page;
int endrow=initialrowcount+this.rows_page;
RectangleF rowbounds = new RectangleF (0, 0, 0, 0);
Draw vertical Lines
Draw the table
for (int i = Initialrowcount i < TheTable.Rows.Count && i< Endrow; i++)
{
DataRow dr = Thetable.rows[i];
int startxposition = this. leftmargin+2; thedatagrid.location.x;
Draw the vertical bar to the right
G.drawline (Thelinepen, this. LeftMargin + this. PageWidth,
Header + TopMargin,
This. LeftMargin + this. PageWidth,
bottom);
int total=thedatagrid.tablestyles[0]. gridcolumnstyles.count-1;
for (int k = 0; k < total; k++)
{
posx+= (Thedatagrid.tablestyles[0]. GRIDCOLUMNSTYLES[K]. Width) * this. Pagewidth/this. Gridwidth;
G.drawline (Thelinepen, this. LeftMargin + POSX,
Header + TopMargin,
This. LeftMargin + POSX,
bottom);
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.