0

I have a hopefully simple question this time: I want to print items which are looped through and printed in 2x2 per page. I'm using a loop for that, and a Rectangle array. That can change though. What's the simplest way to print to the certain part of a graphics? The context is I'm doing it in a print event, using the supplied e.Graphics object - the current code looks like:

public void BeginPrintEvent(object sender, PrintPageEventArgs e)
{
    SizeF TestSize;
    string text = "";
    Image labelImage = new Bitmap((int)e.Graphics.DpiX, (int)e.Graphics.DpiY, e.Graphics);
    Graphics g = e.Graphics;
    Rectangle[] rect = new[] { new Rectangle(0,   0,   419, 581),
                               new Rectangle(419, 0,   419, 581),
                               new Rectangle(0,   581, 419, 581),
                               new Rectangle(419, 581, 419, 581) };

    try
    {
        for (int lblNum = 0; lblNum < 4); lblNum++)
        {
            g.DrawString( // lots of stuffs
            e.Graphics.DrawImage(labelImage, rect[lblNum]);
        }
    }
    catch (Exception exc)
    {
        // Report to user
    }
}

I can't seem to get the imaging right, the sizes tend to be very small so most of the image is lost.

Whoop5
  • 47
  • 2
  • 12
  • You already answered on your question "too small", why your new image has so small dimention? – Sinatr Mar 18 '13 at 15:16
  • @Sinatr Presumably I'm retrieving the size the right way. There's no explicit `Width` or `Height` members in the `e.Graphics` object. All I have is some unholy Clip uses. – Whoop5 Mar 19 '13 at 07:35
  • `Image labelImage = new Bitmap(419, 581, e.Graphics);` – Sinatr Mar 19 '13 at 10:47

1 Answers1

0

Worked it out as:

 Image labelImage = new Bitmap(419 * ((int)e.Graphics.DpiX / 100), 581 * ((int)e.Graphics.DpiX / 100), e.Graphics);

Cheers for noticing the post though Sinatr :)

Whoop5
  • 47
  • 2
  • 12