http://www.c-sharpcorner.com/Graphics/DataGridPrinterMG.asp
解决方案 »
- visual studio 2010 设计视图下方为何看不到控件对象
- treeview控件
- 通过文件流如何打开txt文件???达到双击txt文件的效果,,,解决立马给分!!!!!!!!!!!!!!!!
- 高分求! 求C#网络编程的书籍.类似于写聊天程序,收发文件的程序的入门书.
- .net工具箱的webl选项卡被我误删了,怎么回去呀?
- 上传图片文件到数据库,奇怪的错怪,请高高高手帮忙!!!急急!!!
- 如何判断dataset是否为空????在线等!!
- 请问C#中如何调用WinIO.dll?
- 关于msdn的一个疑问?
- 以前VB中的vbCrlf在C#中怎样实现?功能是文本还行,谢谢!
- 依赖关系的问题
- 串口问题
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int wid=0;
int count = 3;
int p1=linesPrinted;
float linesPerPage = 0;
int x=e.MarginBounds.Left;
int y=e.MarginBounds.Top+20;
printFont=dataGrid1.HeaderFont;
linesPerPage = e.MarginBounds.Height /printFont.GetHeight(e.Graphics) -3;
Pen blackPen = new Pen(Color.Black, 2);
for(int b=0;b<ds.Tables[0].Columns.Count;b++)
{
wid+=dataGrid1.TableStyles[0].GridColumnStyles[b].Width;
}
if(slocation=="dzuo")
{
e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,x,y-20); }
if(slocation=="dzhong")
{
e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,e.MarginBounds.Width/2,y-20); }
if(slocation=="dyou")
{
e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,e.MarginBounds.Width,y-20); }
if(slocation=="xzuo")
{
e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,x,e.MarginBounds.Bottom); }
if(slocation=="xyou")
{
e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,e.MarginBounds.Width-30,e.MarginBounds.Bottom); }
if(slocation=="xzhong")
{
e.Graphics.DrawString(spage1+ipages.ToString()+spage2,dataGrid1.HeaderFont,Brushes.Black,e.MarginBounds.Width/2,e.MarginBounds.Bottom); }
for(int a=0;a<ds.Tables[0].Columns.Count;a++)
{
if(columnwidth[a]!=0)
{
e.Graphics.DrawString(dataGrid1.TableStyles[0].GridColumnStyles[a].HeaderText, dataGrid1.HeaderFont, Brushes.Black, x, y);
x=x+(dataGrid1.TableStyles[0].GridColumnStyles[a].Width*e.MarginBounds.Width/wid);
}
}
y+=(int)printFont.GetHeight(e.Graphics);
x=e.MarginBounds.Left;
e.Graphics.DrawLine(blackPen,x,y,x+e.MarginBounds.Right,y);
y+=2;
while(count < linesPerPage && linesPrinted>=0)
{
if(linesPrinted<=linesPerPage)
{
for(i1=0;i1<=p1-1;i1++)
{
for(int j=0;j<ds.Tables[0].Columns.Count;j++)
{
if(columnwidth[j]!=0)
{
e.Graphics.DrawString(lines[i1+linshi,j],dataGrid1.HeaderFont,Brushes.Black,x,y);
x=x+(dataGrid1.TableStyles[0].GridColumnStyles[j].Width*e.MarginBounds.Width/wid);
}
}
x=e.MarginBounds.Left;
count++;
y+=(int)printFont.GetHeight(e.Graphics);
}
e.HasMorePages=false;
return;
}
else
{
for(i1=0;i1<linesPerPage;i1++)
{
for(int j=0;j<ds.Tables[0].Columns.Count;j++)
{
if(columnwidth[j]!=0)
{
e.Graphics.DrawString(lines[i1+linshi,j],dataGrid1.HeaderFont,Brushes.Black,x,y);
x=x+(dataGrid1.TableStyles[0].GridColumnStyles[j].Width*e.MarginBounds.Width/wid);
}
}
x=e.MarginBounds.Left;
count++;
y+=(int)printFont.GetHeight(e.Graphics);
linesPrinted--;
}
if(linesPrinted>0)
e.HasMorePages=true;
linshi=linshi+i1;
ipages++;
return;
} }
} private void bprint_Click(object sender, System.EventArgs e)
{
if(printDialog1.ShowDialog()==DialogResult.OK)
{
printDocument1.Print();
}