Pregunta

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.

¿Fue útil?

Solución

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 :)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top