|
There is information in the documentation on setting column widths.
|
|
|
|
|
Sir! I just adjusted the AutoSizeColumn in datagridview and it fixes my problem.
This is just incredible, the code will adjust to print Thank you sir for the help
One more thing, Ive seen an tutorial on youtube and it uses "DGV2printerhelper", is it your work also?
|
|
|
|
|
very nice, an option to make the pages horizontal would be appreciated
|
|
|
|
|
Landscape printing is available through the selections on the printer driver at print time and should be fully supported. Unless you were thinking of something else?
Steve G.
|
|
|
|
|
Unbelievable! It's even documented! That's unheard of... But you just saved me a ton of time and aggravation. Thank you very, very much!
|
|
|
|
|
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
this.printDocument1.DefaultPageSettings.Landscape = true;
using (Font fnt1 = new Font("Segoe UI", 12f, FontStyle.Regular))
{
using (Font fnt2 = new Font("Arial", 13f, FontStyle.Bold))
{
e.Graphics.DrawRectangle(Pens.Black, 50, 5, 1000, 30);
e.Graphics.DrawRectangle(Pens.Black, 50, 35, 1000, 30);
e.Graphics.DrawString("test", fnt2, Brushes.Black, new RectangleF(new PointF(500f, 10f), new SizeF(300f, 20f)));
DGVPrinter printer = new DGVPrinter();
|
|
|
|
|
Title and footer accept only strings.I wanna set those rectangles as title i mean.
|
|
|
|
|
What you want to do is possible, but not easy. You would need to take complete control of the graphics context for the drawing, this will allow you to draw your boxes (and anything else you'd like) in the header and footer, title or anywhere else on the page. You would invoke the DataGridViewPrinter using the "Embedded Printing" process described in the documentation.
The upside of doing this is that you can draw anything, anywhere on the page, and make your form look precisely what you want. The downside is that you have to draw everything. The Embedded Printing process will write to a graphics context that you then need to manage.
So, what you want is possible, it's just a matter of how much effort you would be willing to go through to get there.
|
|
|
|
|
I already have the graphics on the post: http://stackoverflow.com/questions/36167909/how-to-print-the-bitmap-on-two-pages
So let's put those graphics before:
this.printDocument1.DefaultPageSettings.Landscape = true;
using (Font fnt1 = new Font("Segoe UI", 12f, FontStyle.Regular))
{
using (Font fnt2 = new Font("Arial", 13f, FontStyle.Bold))
{
e.Graphics.DrawString("just a text", fnt2, Brushes.Black, new RectangleF(new PointF(500f, 10f), new SizeF(300f, 20f)));
e.Graphics.DrawRectangle(Pens.Black, 50, 5, 1000, 30);
e.Graphics.DrawRectangle(Pens.Black, 50, 35, 1000, 30);
e.Graphics.DrawString("just a test", fnt2, Brushes.Black, new RectangleF(new PointF(280f, 40f), new SizeF(700f, 20f)));
e.Graphics.DrawRectangle(Pens.Black, 50, 70, 300, 20);
e.Graphics.DrawString("some data :", fnt1, Brushes.Black, new RectangleF(new PointF(55f, 70f), new SizeF(500f, 20f)));
e.Graphics.DrawRectangle(Pens.Black, 50, 90, 300, 20);
e.Graphics.DrawString("some data :", fnt1, Brushes.Black, new RectangleF(new PointF(55f, 90f), new SizeF(300f, 20f)));
e.Graphics.DrawRectangle(Pens.Black, 350, 70, 700, 20);
e.Graphics.DrawString("str", fnt1, Brushes.Black, new RectangleF(new PointF(600f, 70f), new SizeF(300f, 20f)));
e.Graphics.DrawRectangle(Pens.Black, 350, 90, 700, 20);
e.Graphics.DrawString("str", fnt1, Brushes.Black, new RectangleF(new PointF(600f, 90f), new SizeF(300f, 20f)));
e.Graphics.DrawRectangle(Pens.Black, 50, 110, 300, 20);
e.Graphics.DrawRectangle(Pens.Black, 350, 110, 700, 20);
e.Graphics.DrawString("some data :", fnt1, Brushes.Black, new RectangleF(new PointF(55, 110), new SizeF(300f, 20f)));
e.Graphics.DrawString("str", fnt1, Brushes.Black, new RectangleF(new PointF(600, 110), new SizeF(300f, 20f)));
and those graphics after the datagridview:
e.Graphics.DrawRectangle(Pens.Black, 50, 640, 300, 20);
e.Graphics.DrawString("some data :", fnt1, Brushes.Black, new RectangleF(new PointF(50, 640), new SizeF(300f, 20f)));
e.Graphics.DrawRectangle(Pens.Black, 350, 640, 700, 20);
e.Graphics.DrawString("int", fnt1, Brushes.Black, new RectangleF(new PointF(700, 640), new SizeF(300f, 20f)));
e.Graphics.DrawString("some data....", fnt1, Brushes.Black, new RectangleF(new PointF(50, 660), new SizeF(1000f, 70f)));
e.Graphics.DrawString("my sign goes here", fnt1, Brushes.Black, new RectangleF(new PointF(650, 730), new SizeF(300f, 20f)));
}
}
Can u give me an example how to use them before and after the datagridview?
I don't get the "embed printing" of the control,didn't understand that part.
Thanks in advance.
|
|
|
|
|
You're very close. You can have DGVPrinter print to your graphics context, so that the grid will appear between your 'before' and 'after'. In the example on page 5 of the documentation you can see that the DGVPrinter object is being passed a graphics context and a rectangle within which to print. You can call DGVPrinter and pass in the same graphics context you are using in your example above, along with a rectangle that defines the working space between your 'before' and your 'after' graphics.
|
|
|
|
|
I am using the example from the documentation but i got confused,i can't pass the same graphics context.
private void printDataGridView(object sender, PrintPageEventArgs e)
{
var print = new DGVPrinter();
print.RowHeight = DGVPrinter.RowHeightSetting.CellHeight;
e.HasMorePages = print.EmbeddedPrint(dgvTheory, e.Graphics, new Rectangle(30, 150, 960, 500));
}
Where to put and how to call the printDataGridView?That i mean.
Should i call it on printpage or on button click?
I just called that in the middle of the graphics and i got
Err:
There is no argument given that corresponds to the required formal parameter 'e' of 'Main.printDataGridView(object, PrintPageEventArgs)'
Thank you very much for your fast replies mate!
modified 23-Mar-16 10:19am.
|
|
|
|
|
Page 5 of the current doc has an example where a graphics context is passed in to DGVPrinter. So, you would pass on your graphics context and a rectangle with the available space. Read the section of the doc titled "Embedded printing". Your situation is exactly what that was designed for.
Good luck! I will probably not be able to respond for a day or so - on vacation.
|
|
|
|
|
thank you very much my friend,have a nice trip.
|
|
|
|
|
Hi, I have 16 columns to print and i get ovrer to pages. Wich setup i must make to fit to page all columns ? Thx Ljuban
|
|
|
|
|
Under normal circumstances, you can set the value of the ColumnWidth property to be "ColumnWidthSetting.Porportional". If this doesn't seem to work for you and you have columns that are normally too wide for the page (or, simply too many columns to fit on one page) you can manually set the column widths narrower using the "ColumnWidths" property so that all columns will fit.
Steve G.
|
|
|
|
|
Hi,
it's really a fantastic tool. Good job.
Can you explain how the sysntax for FixedColumns is.
Thanks in advance
|
|
|
|
|
This is listed in the documentation, page 15. Look for the "ColumnWidths" property for an explanation and an example.
Steve G.
|
|
|
|
|
Hello,
I have a DataGridView where I have set the header alignment for a certain column to middle right with the following line:
columnName.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
The other columns are set to middle left (default). The alignment is correct in the DataGridView itself but when I want to print it, the alignment for that certain column is NOT set to middle right but to middle left.
Is this a bug? How can I fix it?
|
|
|
|
|
Hi
I use it to print receipt if i don't use the footer it print the table size in one paper and cut in the end of the table in the correct size if i use the footer it give me huge gap between the table and footer .
this my code .
Also I specified printer name to use it to print to it it still use the default printer in the system.
Dim Printer = New DGVPrinter
Printer.PrintMargins.Right = 0
Printer.PrintMargins.Left = 0
Printer.PrintMargins.Bottom = 0
Printer.PrintMargins.Top = 0
Printer.Title = companynamex
Printer.SubTitle = slogn
Printer.SubTitleSpacing = 10
Printer.TitleFont = New Font("Arial", 16, FontStyle.Bold Or FontStyle.Underline)
Printer.SubTitleFormatFlags = StringFormatFlags.LineLimit Or StringFormatFlags.NoClip
Printer.FooterFont = New Font("Arial", 12, FontStyle.Bold Or FontStyle.Underline)
Printer.PageNumbers = False
Printer.TableAlignment = DGVPrinter.Alignment.Center
Printer.PageNumberInHeader = False
Printer.PorportionalColumns = True
Printer.HeaderCellAlignment = StringAlignment.Center
Printer.HeaderCellAlignment = StringAlignment.Center
Printer.PorportionalColumns = True
Printer.TableAlignment = DGVPrinter.Alignment.NotSet
Printer.ColumnWidth = DGVPrinter.ColumnWidthSetting.Porportional
Printer.KeepRowsTogether = True
Printer.ColumnWidths.Add("CoSubTotal", 50)
Printer.ColumnWidths.Add("CoName", 110)
Printer.ColumnWidths.Add("CoQty", 25)
Printer.ColumnWidths.Add("CoPriceOut", 50)
Printer.Footer = "SysBeta "
Printer.FooterSpacing =0
Printer.PrinterName = "Smart-Pos"
Printer.HideColumns().Add("CoBarcode")
Printer.PrintNoDisplay(Me.DvPos)
|
|
|
|
|
A question that if we want to change the print landscape to potrait
|
|
|
|
|
You can do this through the print dialog without any problems. The code will adjust.
|
|
|
|
|
For some reason (probably operator error :P ) CodeProject is no longer notifying me when someone posts in my articles. If you've posted and I've not replied, it's not that I'm ignoring you, it's that I genuinely have no idea that you've posted here.
Steve G.
|
|
|
|
|
Hi,
is it possible to print two Datagrids on one Page ?
|
|
|
|
|
Great job! But one question: Is it possible to print in headers dgv.Column.HeaderText? Currently it prints dgv.Column.Name...
I am sorry! All is OK. DGVPrinter prints the HeaderText.
dgv.Columns["T1"].HeaderText = "TotalSum";
Thank you for the great job!
modified 4-Jun-15 8:34am.
|
|
|
|
|
want to print only one page wide, not page1 part1 page1 part2, how can i achieve that?
|
|
|
|
|