如果说你只想打印DATAGRID中的内容,那不行,只能打印页面,我说的是在WEB中的,如果在WINFORM是可以的,代码:
用IE的打印就行了
用IE的打印就行了
解决方案 »
- 柯达扫描控件axImgScan1 如何设置扫描高宽
- 请教Linq ExecuteQuery的类型如何定义?
- web项目发布到服务器上相关问题
- 在网上看了个PetShop4的详解,有36页之多啊!
- 简单问题 返回一个DataTable的表格
- 怎么给数组赋值?(不是一个一个的给数组元素赋值)
- 请教:使用ADOX能否在创建一个ACCESS数据库的同时,生成两个新的数据表
- 有熟悉正弦曲线拟合的朋友们,请给些资料。
- 请各位C#高手帮忙解决一下!
- 如何统筹安排和管理各个项目并使之成为一个完整系统?
- 用VS.Net自带的安装程序,如何实现有选择的安装,比如安装office的时候,可以选择安装word,excel,也可以选择不安装?
- 为什么增加或删除时会执行两次? 急!!!
顺便说明一下在web下的情况?
可以在csdn上搜索一下相关的帖子,应该好解决。
{
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();
}