TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Juan Matrix
NA
3
0
I can not print all pages
Aug 26 2008 3:04 PM
I need help with programming in C # program SharpDevelop,
as print the full contents of the ranks datagridview with a header as this block of code
google search for prints and works part. I explain:
a. - if the datagridview has less than 22 Rows prints (use class preview) better and complete the road and only one sheet should print
b. - if the datagridview has 59 rows me prints (use class preview) several sheets and I always Printed and cancel all leaves, the contents of the first page
I think I reset any accountant or content of the buffer or something.
The program has a button that calls the routine imprime_inventario.
if they can see the code shown what I show.
I am hoping to help them appreciate their contribution.
Thanks Friends.
Atte.
Matrix
private void imprime_inventario(object sender, PrintPageEventArgs e)
{
ArrayList arrColumnLefts=new ArrayList();
ArrayList arrColumnWidths=new ArrayList();
int iCellHeight=0;
int iCount=0;
bool bFirstPage =true;
bool bNewPage=true;
int iTotalWidth=0;
foreach (DataGridViewColumn dgvGridCol in dataGridView1.Columns) {
iTotalWidth +=dgvGridCol.Width;
}
StringFormat strFormat=new StringFormat();
strFormat.Alignment=StringAlignment.Near;
strFormat.LineAlignment=StringAlignment.Center;
strFormat.Trimming=StringTrimming.EllipsisCharacter;
int iLeftMargin = e.MarginBounds.Left;
int iTopMargin = e.MarginBounds.Top;
bool bMorePagesToPrint=false;
int iTmpWidth=0;
int iHeaderHeight=0;
arrColumnLefts.Clear();
arrColumnWidths.Clear();
Font PrintFont=new Font(dataGridView1.Font,FontStyle.Bold);
if(bFirstPage){
foreach(DataGridViewColumn GridCol in dataGridView1.Columns) {
iTmpWidth=(int)(Math.Floor((double)((double)GridCol.Width/(double)iTotalWidth * (double)iTotalWidth* ((double)e.MarginBounds.Width/(double)iTotalWidth))));
iHeaderHeight=(int)(e.Graphics.MeasureString(GridCol.HeaderText,GridCol.InheritedStyle.Font,iTmpWidth).Height)+11;
arrColumnLefts.Add(iLeftMargin);
arrColumnWidths.Add(iTmpWidth);
iLeftMargin +=iTmpWidth;
}
}
int iRow =0;
float linePerPage=(e.MarginBounds.Height/PrintFont.GetHeight(e.Graphics));
while (iRow <=dataGridView1.Rows.Count-1) {
DataGridViewRow GridRow=dataGridView1.Rows[iRow];
iCellHeight=GridRow.Height+5;
if(iTopMargin+iCellHeight>=e.MarginBounds.Height+e.MarginBounds.Top){
bNewPage=true;
bFirstPage=false;
bMorePagesToPrint=true;
break;
}
else{
if(bNewPage){
e.Graphics.DrawString("MARBETE",new Font(dataGridView1.Font,FontStyle.Bold),Brushes.Black,e.MarginBounds.Left,e.MarginBounds.Top-e.Graphics.MeasureString("MARBETE",new Font(dataGridView1.Font,FontStyle.Bold),e.MarginBounds.Width).Height-13);
String strDate =DateTime.Now.ToLongDateString()+""+DateTime.Now.ToShortDateString();
e.Graphics.DrawString(strDate,new Font(dataGridView1.Font,FontStyle.Bold),Brushes.Black,e.MarginBounds.Left+(e.MarginBounds.Width-e.Graphics.MeasureString(strDate, new Font(dataGridView1.Font,FontStyle.Bold),e.MarginBounds.Width).Width),e.MarginBounds.Top-e.Graphics.MeasureString("MARBETE",new Font(dataGridView1.Font,FontStyle.Bold),e.MarginBounds.Width).Height-13);
iTopMargin=e.MarginBounds.Top;
foreach(DataGridViewColumn GridCol in dataGridView1.Columns){
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), new Rectangle((int)arrColumnLefts[iCount],iTopMargin,(int)arrColumnWidths[iCount],iHeaderHeight));
e.Graphics.DrawRectangle(Pens.Black,new Rectangle((int)arrColumnLefts[iCount],iTopMargin,(int)arrColumnWidths[iCount],iHeaderHeight));
e.Graphics.DrawString(GridCol.HeaderText,GridCol.InheritedStyle.Font,new SolidBrush(GridCol.InheritedStyle.ForeColor), new RectangleF((int)arrColumnLefts[iCount],iTopMargin,(int)arrColumnWidths[iCount],iHeaderHeight), strFormat);
//new SolidBrush(Color.ForestGreen)
iCount++;
}
bNewPage=false;
iTopMargin+=iHeaderHeight;
}//Fin If
iCount=0;
foreach(DataGridViewCell Cel in GridRow.Cells){
if(Cel.Value !=null){
e.Graphics.DrawString(Cel.Value.ToString(),Cel.InheritedStyle.Font, new SolidBrush(Cel.InheritedStyle.ForeColor), new RectangleF((int)arrColumnLefts[iCount],(float)iTopMargin,(int)arrColumnWidths[iCount],(float)iCellHeight),strFormat);
}
e.Graphics.DrawRectangle(Pens.Black,new Rectangle((int)arrColumnLefts[iCount],iTopMargin,(int)arrColumnWidths[iCount],iCellHeight));
iCount++;
}
}//fin Else
iRow++;
iTopMargin+=iCellHeight;
} //Fin while
if(bMorePagesToPrint)
e.HasMorePages=true;
else
e.HasMorePages=false;
}
void Button2Click(object sender, EventArgs e)
{
PrintPreviewDialog dlg = new PrintPreviewDialog();
PrintDocument PD =new PrintDocument();
PD.PrinterSettings.FromPage=0;
PD.PrinterSettings.ToPage=0;
PD.PrinterSettings.PrintRange=PrintRange.AllPages;
PD.DefaultPageSettings.Landscape=true;
PD.PrintPage += new PrintPageEventHandler(this.imprime_inventario);
dlg.Document=PD;
dlg.ShowDialog();
}//Fin boton Imprimir
Reply
Answers (
1
)
which features are added in asp.net 3.5
Master page