❔ Printing text using e.Graphics and label bounds
I'm trying to print what is shown on a winform and realized that using a bitmap just wouldn't give me the results I needed, and that I'd need to use e.Graphics to just manually draw everything. While time consuming, it's not a huge deal since it's just a lot of similarly named labels. The problem I'm having is that label text isn't being put in the correct place when I use label.bounds.location.
I've attached a partial screenshot of what I see in the form and also what I'm seeing in the print preview.
Also, here's the code I'm using:
I've attached a partial screenshot of what I see in the form and also what I'm seeing in the print preview.
Also, here's the code I'm using:
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//e.Graphics.DrawImage(memoryImage, e.MarginBounds);
Pen blackPen = new Pen(Color.Black);
Brush blackBrush = new SolidBrush(Color.Black);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewRoot.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSSSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSSDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSDSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSDDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDSSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDSDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDDSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDDDam.Bounds);
e.Graphics.DrawString(lblFarmNameRoot.Text, lblFarmNameRoot.Font, blackBrush, lblFarmNameRoot.Bounds);
e.Graphics.DrawString(lblRabbitNameRoot.Text, lblRabbitNameRoot.Font, blackBrush, lblRabbitNameRoot.Bounds.Location);
e.Graphics.DrawString(lblEarNumRoot.Text, lblEarNumRoot.Font, blackBrush, lblEarNumRoot.Bounds.Location);
e.Graphics.DrawString(lblColorRoot.Text, lblColorRoot.Font, blackBrush, lblColorRoot.Bounds.Location);
e.Graphics.DrawString(lblRegNumRoot.Text, lblRegNumRoot.Font, blackBrush, lblRegNumRoot.Bounds.Location);
e.Graphics.DrawString(lblGCNumRoot.Text, lblGCNumRoot.Font, blackBrush, lblGCNumRoot.Bounds.Location);
e.Graphics.DrawString(lblSexRoot.Text, lblSexRoot.Font, blackBrush, lblSexRoot.Bounds.Location);
e.Graphics.DrawString(lblBirthdayRoot.Text, lblBirthdayRoot.Font, blackBrush, lblBirthdayRoot.Bounds.Location);
e.Graphics.DrawString(lblWeightRoot.Text, lblWeightRoot.Font, blackBrush, lblWeightRoot.Bounds.Location);
}private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//e.Graphics.DrawImage(memoryImage, e.MarginBounds);
Pen blackPen = new Pen(Color.Black);
Brush blackBrush = new SolidBrush(Color.Black);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewRoot.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSSSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSSDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSDSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewSDDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDSSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDSDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDDam.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDDSire.Bounds);
e.Graphics.DrawRectangle(blackPen, rabbitBoxViewDDDam.Bounds);
e.Graphics.DrawString(lblFarmNameRoot.Text, lblFarmNameRoot.Font, blackBrush, lblFarmNameRoot.Bounds);
e.Graphics.DrawString(lblRabbitNameRoot.Text, lblRabbitNameRoot.Font, blackBrush, lblRabbitNameRoot.Bounds.Location);
e.Graphics.DrawString(lblEarNumRoot.Text, lblEarNumRoot.Font, blackBrush, lblEarNumRoot.Bounds.Location);
e.Graphics.DrawString(lblColorRoot.Text, lblColorRoot.Font, blackBrush, lblColorRoot.Bounds.Location);
e.Graphics.DrawString(lblRegNumRoot.Text, lblRegNumRoot.Font, blackBrush, lblRegNumRoot.Bounds.Location);
e.Graphics.DrawString(lblGCNumRoot.Text, lblGCNumRoot.Font, blackBrush, lblGCNumRoot.Bounds.Location);
e.Graphics.DrawString(lblSexRoot.Text, lblSexRoot.Font, blackBrush, lblSexRoot.Bounds.Location);
e.Graphics.DrawString(lblBirthdayRoot.Text, lblBirthdayRoot.Font, blackBrush, lblBirthdayRoot.Bounds.Location);
e.Graphics.DrawString(lblWeightRoot.Text, lblWeightRoot.Font, blackBrush, lblWeightRoot.Bounds.Location);
}

