position of the printed out datagrid
-
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PaintEventArgs myPaintArgs = new PaintEventArgs (e.Graphics, new Rectangle(0,0,datagrid1.Width,datagrid1.Height)); this.InvokePaint(dg, myPaintArgs); }
this is the coding i used to print out datagrid, the X and Y is set to 0 and 0, the datagrid print out correctly at exactly upper left corner of the paper. then i modify the coding.private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PaintEventArgs myPaintArgs = new PaintEventArgs (e.Graphics, new Rectangle(50,50,datagrid1.Width,datagrid1.Height)); this.InvokePaint(dg, myPaintArgs); }
i change the cordinates to 50,50, but y the datagrid still print at the same position for cordinates 0,0??i do not wan the datagrid to be printed at that position!anyone can help me out with this??Thz! -
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PaintEventArgs myPaintArgs = new PaintEventArgs (e.Graphics, new Rectangle(0,0,datagrid1.Width,datagrid1.Height)); this.InvokePaint(dg, myPaintArgs); }
this is the coding i used to print out datagrid, the X and Y is set to 0 and 0, the datagrid print out correctly at exactly upper left corner of the paper. then i modify the coding.private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { PaintEventArgs myPaintArgs = new PaintEventArgs (e.Graphics, new Rectangle(50,50,datagrid1.Width,datagrid1.Height)); this.InvokePaint(dg, myPaintArgs); }
i change the cordinates to 50,50, but y the datagrid still print at the same position for cordinates 0,0??i do not wan the datagrid to be printed at that position!anyone can help me out with this??Thz!You could create a bitmap with the needed dimension, create a Graphics object for it, paint the grid to this bitmap and finally draw the bitmap onto the page:
Bitmap b = new Bitmap(datagrid1.Width,datagrid1.Height);
using (Graphics bg = GraphicsFromImage(b)) {
PaintEventArgs myPaintArgs = new PaintEventArgs (bg , new Rectangle(0,0,datagrid1.Width,datagrid1.Height));
this.InvokePaint(dg, myPaintArgs);
}
e.Graphics.DrawImageUnscaled(b, 50, 50); -
You could create a bitmap with the needed dimension, create a Graphics object for it, paint the grid to this bitmap and finally draw the bitmap onto the page:
Bitmap b = new Bitmap(datagrid1.Width,datagrid1.Height);
using (Graphics bg = GraphicsFromImage(b)) {
PaintEventArgs myPaintArgs = new PaintEventArgs (bg , new Rectangle(0,0,datagrid1.Width,datagrid1.Height));
this.InvokePaint(dg, myPaintArgs);
}
e.Graphics.DrawImageUnscaled(b, 50, 50);thz man!the coding works for me.. but there is another problem, my datagrid has been loaded with a datatable contains 31 records, under screen resolution of 1024*768, the screen is able to show and print out all the records, but if user change screen resolution to 800*600, the records that can show in one screen is only 21 records, the rest of the records needed to be scroll down to view, then the datagrid printed out only contains 21 records that can be shown on the screen... wat should i do??:doh: