It is necessary to print a cash order. I took the panel, assigned it to bg-image and asked her the size of A4 paper. In the place where the values ​​are needed, Labels were made.

print using code

private void toolStripSplitButton1_ButtonClick(object sender, EventArgs e) { printDocument1.Print(); } private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { printDocument1.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0); var bitmap = new Bitmap(panel1.Width, panel1.Height); panel1.DrawToBitmap(bitmap, new Rectangle(panel1.Location, bitmap.Size)); e.Graphics.DrawImage(bitmap,new Point(0,0)); } 

here is the result. crooked prints

Indentations do not disappear, what to do? help solve the problem. Or is there a better alternative to printing a template document?

  • one
    And what is missing in the solution proposed in the question? - 0xdb
  • The solution for WPF ran through just: ru.stackoverflow.com/q/706253/10105 - VladD
  • Something tells me that you did not correctly set either the margins or the orientation of the page (by default, vertical or portrait, this is how you like it). In the code, there are no obvious blunders when working with GDI. Look at the next question and answer and print a preview without printing, it should be seen that they missed. - rdorn
  • Well, until I forgot, not all printers can print without borders (or rather, some only know how - typographical, for example), so you need to adjust the size of the print area to fit inside the margins - rdorn

2 answers 2

for everything to work as it should, you need to change this:

  panel1.DrawToBitmap(bitmap, new Rectangle(panel1.Location, bitmap.Size)); 

on

  panel1.DrawToBitmap(bitmap, new Rectangle(Point.Empty, bitmap.Size)); 

those. draw from the origin.

  • one
    Add in the answer what exactly the problem was. Of course, I found it, but at first glance the code here is identical in the question. This is not good at all. Under any post there is a button Edit - rdorn

But in the end I refused it.


The original template was in Excel. I saved it as html, and I just open html in webbrowser. Printing this control makes it easy and easy.