Print using custom margins in .NET

I use vb.Net and standard .NET printing routines to print labels through Dymo printers. My application must support any type of label printer. Because the dymo driver is in the control panel There are no accessible margins, and the control panel is restrictive for most of my users, so I use the app to set the margins.

I use the margins set in the app Replace the margins in the PrintDocument, which is great, but I also have some code for calculating the text size and formatting based on the width of the printable area. I can never make the printable area resize? All margin settings are based on the top and left margins to diverge the entire graph down and to the right. The printable area and VisibleClipBounds in the graph object will never change? When this happens, the text will only flow from the bottom right corner of the page, so it will not follow the right and bottom margins at all.

Is this normal behavior? Do I have to do more processing in the application to calculate the printable area myself based on my margins and initial page size?

'Code to setup PrintDocument
MyDocument.DefaultPageSettings.Margins = New Margins(Printers.LabelPrinter.MarginLeft / 0.254, Printers.LabelPrinter.MarginRight / 0.254, Printers. LabelPrinter.MarginTop / 0.254, Printers.LabelPrinter.MarginBottom / 0.254)
MyDocument.OriginAtMargins = True


'Code that runs during the MyDocument.Print event
width = e.Graphics.VisibleClipBounds.Width
height = e.Graphics.VisibleClipBounds.Height
'Calculate best fit text size here and update graphics object

Solved it. My example Cheng just uses the Graphics object instead of the full eventargs of the Print event.

The print event contains the MarginBounds property, which returns a rectangle of size after applying the margins, so it works fine.

solved it. My routine just uses the Graphics object instead of the full eventargs of the Print event.

The print event contains the MarginBounds property, which returns a sized rectangle after applying the margins, so it works fine.

(Add this as an answer because there was not enough credit to do this at the time And hope this will help those who see this question without an answer).

I use vb.Net and standard .NET printing routines to print labels via Dymo printer , My application must support any type of label printer. Because dymo The driver has no accessible margins in the control panel, and the control panel is restrictive for most of my users, so I use the app to set the margins.

I use the app The margins set in the program replace the margins in the PrintDocument, which is good, but I also have some code for calculating the text size and format based on the width of the printable area. I can never make the printable area change size? All margin settings are based on the top and left margins to diverge the entire graph down and to the right. The printable area and VisibleClipBounds in the graph object will never change? When this happens, the text will only flow from the bottom right corner of the page, so it will not follow the right and bottom margins at all.

Is this normal behavior? Do I have to do more processing in the application to calculate the printable area myself based on my margins and initial page size?

'Code to setup PrintDocument
MyDocument.DefaultPageSettings.Margins = New Margins(Printers.LabelPrinter.MarginLeft / 0.254, Printers.LabelPrinter.MarginRight / 0.254, Printers. LabelPrinter.MarginTop / 0.254, Printers.LabelPrinter.MarginBottom / 0.254)
MyDocument.OriginAtMargins = True


'Code that runs during the MyDocument.Print event
width = e.Graphics.VisibleClipBounds.Width
height = e.Graphics.VisibleClipBounds.Height
'Calculate best fit text size here and update graphics object

Solved it. My example Cheng just uses the Graphics object instead of the full eventargs of the Print event.

The print event contains the MarginBounds property, which returns a rectangle of size after applying the margins, so it works fine.

p>

Solved it. My routine just uses the Graphics object instead of the full eventargs of the Print event.

The print event contains the MarginBounds property, the The property returns a sized rectangle after applying the margins, so it works fine.

(Added this as an answer because there was not enough reputation to do this at the time, and hope this will help those who see this problem People don’t have an answer).

Leave a Comment

Your email address will not be published.