First you have to decide which you want:
- Print within a fixed 2 inch space.
- Print as much height as it needs to accommodate all text.
If you choose #1, your space is inflexible and cropping is inevitable.
If you choose #2, then you will need to calculate the total height, and then set your starting point according to that:
This is not a working example, but should be enough to get you going:
String strLines = String.Empty;
foreach (DataGridViewRow item in this.dgTest.Rows)
{
if (!String.IsNullOrEmpty(strLines))
strLines += "\n";
strLines += item.Cells[0].Value;
}
Size proposedSize = new Size(100, 100); //maximum size you would ever want to allow
StringFormat flags = new StringFormat(StringFormatFlags.LineLimit); //wraps
Size textSize = TextRenderer.MeasureText(strLines, fontNormal, proposedSize, flags);
Int32 xOffset = e.MarginBounds.Right - textSize.Width; //pad?
Int32 yOffset = e.MarginBounds.Bottom - textSize.Height; //pad?
e.Graphics.DrawString(strLines, fontNormal, Brushes.Black, xOffset, yOffset, flags);