# Setting Printer Margins



## fpat (Nov 4, 2000)

How can I set the margins to be used by my printer when printing a string?


----------



## Snake~eyes (Apr 18, 2002)

what language?


----------



## fpat (Nov 4, 2000)

VB 6


----------



## TimCottee (Oct 10, 2001)

I think you need to explain a little more what you actually want. Generally speaking you don't need to control the margins as such you just need to ensure that your string is correctly positioned within them on the page. Can you post a segment of the code and explain what it is that you are trying to do. Then we can certainly come up with an appropriate solution.


----------



## fpat (Nov 4, 2000)

I am really trying to find a way to add a Page Setup dialog box like that used in Word. It lets you set page margins and size, among other things that the Printer dialog box does not.


----------



## thecaptainjs (Jun 14, 2002)

I want to do the same thing. 
Here is the problem. 
I am trying to print something from a text box (VB6 by the way)
when the printer prints it, it has to lineup with the form its printing on
When i go to other printers (other then the one i am using), the margins are screwed up, they are to small. So i want to set the margins so that everything fits. Please help I am at a loss here
printer.setwidth, and the rest of those controls arent doing anything. I may just not know how to use them, but HELP!!!


----------



## briankm (Jun 12, 2002)

When using the VB6 Printer object: Use the Printer.CurrentX property to set where the text is to appear from the left edge; and use the Printer.CurrentY property to set where the text is to appear from the top edge. If you want better control, you can use the WIN API's or a third party printer control.

Brian


----------



## thecaptainjs (Jun 14, 2002)

Well the currenty is working great, but the currentx is only working for the first line, any ideas?


----------



## briankm (Jun 12, 2002)

thecaptainjs,

Here's how you can use CurrentX, CurrentY, TextHeight, TextWidth, ScaleHeight and ScaleWidth of the Printer object in VB to print on a printer (which is not always the best way to do printing). This method is best when you need to print onto a pre-printed form. For straight text output, you may just want to write to a temp file and shell to notepad....

CurrentX and CurrentY are used to position the pen point for graphics and print output on a form, picturebox and the printer object. You can use the same methods and properties for each. The pen point is used for the first character when outputting text. Text will then flow from that point on. To stop at a margin, you must manually stop output and handle wrapping yourself.

====
When you Print a fragment of text, you can use the following:
1. lngNumCharsPerLine = (Printer.ScaleWidth - (lngMarginWidth *2))\Printer.TextWidth to see how many characters will print on one line for a fixed width font. For non-fixed width fonts use Printer.TextWidth(strTextToPrint) to see if the line of text will fit within your print area. Embedded CRLF's will wrap text but will print all lines after the first line at a CurrentX = 0;

2. After printing a single line of text, use Printer.CurrentY = (Printer.CurrentY + Printer.TextHeight) to set your new CurrentY and reset your Printer.CurrentX = lngMarginWidth; and

3. When Printer.CurrentY >= (Printer.Scaleheight - (lngTopMargin + lngBottomMargin)) then you are onto a new page.


As a tip, write a generic Function to print all the lines of text, and another to Draw lines, etc....

Brian


----------

