0
private void printD_PrintPage(object sender, PrintPageEventArgs e)
    {
        Bitmap memoryimg;
        Panel p = BillBody;
        Graphics g = p.CreateGraphics();
        memoryimg = new Bitmap(p.Width, p.Height);
        p.DrawToBitmap(memoryimg, new Rectangle(0, 0, p.Width, p.Height));
        Rectangle rec = e.PageBounds;
        e.Graphics.DrawImage(memoryimg, (rec.Width / 2) - (BillBody.Width / 2), 10);
    }

My Result here

Cilck to see

even I used code SetResolution(float xDpi, float yDpi) Method like this

private void printD_PrintPage(object sender, PrintPageEventArgs e)
    {
        Bitmap memoryimg;
        Panel p = BillBody;
        Graphics g = p.CreateGraphics();
        memoryimg = new Bitmap(p.Width, p.Height,g);
        memoryimg.SetResolution(600, 600);
        p.DrawToBitmap(memoryimg, new Rectangle(0, 0, p.Width, p.Height));
        Rectangle rec = e.PageBounds;
        e.Graphics.DrawImage(memoryimg, (rec.Width / 2) - (BillBody.Width / 2), 10);
    }

But this time this Happen See Here Can Anyone Help me

Mudassar
  • 11
  • 3
  • 1
    Step one: Never use `CreateGraphics` (unless you really know what you do) !! - Instead use `e.Graphics` from the PrintPage params!! Then report back.. – TaW Mar 22 '22 at 08:43
  • Basically I am a web developer and I am new in C# from application I never not what the `CreateGraphics` did I just Copy paste some codes – Mudassar Mar 22 '22 at 09:28
  • Well it does have its uses e.g. when drawing into bitmaps. But for Paint and Print events always use the e.Graphics param the method provides. [Example](https://stackoverflow.com/questions/28560319/generate-staff-card/28580657#28580657) – TaW Mar 22 '22 at 13:57
  • `e.Graphic` also not working it's give same result like `setResolution()` – Mudassar Mar 22 '22 at 15:02
  • Well, did you set the pageunits and the scale? [Example](https://stackoverflow.com/questions/25709759/printing-fixed-size-image-with-different-printing-resolutions-doesnt-change-pri/25710753#25710753). DrawImage will honor the resolution and with 600 dpi it will make the image really small, esp. if it originally came for the screen resolution (ca. 100dpi, probably) So dump that. - That aside: really good print resolution can't be had when dumping screen controls to the printer. You need to write a full scale printpage routine.. – TaW Mar 22 '22 at 15:33
  • Sorry to say But I can't get Better resolution even I Edit many types of code Please can you write some code of `printDocument` or check and improve the above code lines for me – Mudassar Mar 22 '22 at 17:11
  • No, I can't create non-existent information for you. Your original image contains a screenshot so there is not a lot of pixels to begin with. You can scale them up (you did read the example, no??) but that won't make it look good; esp the fonts will look bad. – TaW Mar 22 '22 at 18:44
  • Example No 2, So what the Best way to print out the panel. is `DrawToString` method possible with panel?? – Mudassar Mar 23 '22 at 09:24
  • DrawString can print high quality text when called in a PrintPage event. I don't see what a Panel could do in that case. Remember: a Panel is a control and consists of very few pixels.. – TaW Mar 23 '22 at 11:05
  • Thank you sir for helping a lot ٩(◕‿◕)۶ – Mudassar Mar 25 '22 at 10:21

0 Answers0