Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawToBitmap on Panel is blank
    primarykey
    data
    text
    <p>So I've written a class that has a stores some test results info and then a control that displays that info to the user. I want to put a print function on this class to draw the control at a full page size and print it. However it always comes out blank. The code see the panel as a control because it could be some other type of value. I figure there must be something simple I'm missing.</p> <pre><code>void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { System.Drawing.Size oldSize = printData.Size; printData.Size = new System.Drawing.Size(e.MarginBounds.Width, e.MarginBounds.Height); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(printData.Size.Width, printData.Size.Height); InvertZOrderOfControls(printData.Controls); printData.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, printData.Size.Width, printData.Size.Height)); InvertZOrderOfControls(printData.Controls); e.Graphics.DrawImage(bitmap, e.MarginBounds.Location); bitmap.Save(@"C:\Users\jdudley\Documents\File.bmp"); printData.Size = oldSize; } </code></pre> <p>Following this advice of <a href="http://www.daniweb.com/software-development/csharp/threads/298209/printing-panel-in-c-desktop-application" rel="nofollow">this thread</a> inverted the Z-Order of the controls but it didn't change anything. The save call was added for debugging. It looks like it's actually rendering the background color of the panel without any of the controls.</p> <p>Edit: This is in the context of printing but I have not issue with printing what so ever. My error is in creating the bitmap. The save line I added proves this because it creates a blank bitmap file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload