❔ 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:
14 Replies
Have you tried to debug cour code? Maybe the location is set to (0, 0) somewhere
good Idea
Yeah, it's not very far from where it's displaying
compared to the location of the box
That is because the location of the label is relative to the box
aha!
That makes sense
so I should do the box's bounds + the label
Yeah that'd work
that looks a lot better
Thanks
Is there a way to use e.MarginBounds when drawing rectangles and text manually? My form is apparently larger than the print area
Not sure how MarginBounds would help you have to somehow project the image you wanna print to the print area
When I was just doing a bitmap of the screen I could use e.MarginBounds in the DrawImage to tell it to print to the bounds of the page
But I guess that's not an option since I'm manually drawing everything now
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.