By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,312 Members | 1,877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,312 IT Pros & Developers. It's quick & easy.

Controlling XY position of printer output

P: 6
Please excuse my cluelessness on the subject - this is the first time I've worked with printing in VB (and it may be the last) and the more I work with it, the more confused I become...

First, I'm setting the printer's scale and the X,Y position of the output:

Expand|Select|Wrap|Line Numbers
  1. Sub SetLargePrinterScale(obj As Object, VertPosition As Single)
  2. Dim Owid As Single
  3. Dim Ohgt As Single
  4. Dim Pwid As Single
  5. Dim Phgt As Single
  6. Dim Xmid As Single
  7. Dim Ymid As Single
  8. Dim S As Single
  9. Dim ScaleFactor As Single
  10.  
  11.     ScaleFactor = (50 - frmPrint.Slider3.Value) / 10
  12.  
  13.     Owid = obj.ScaleX(obj.ScaleWidth, obj.ScaleMode, vbPixels)
  14.     Ohgt = obj.ScaleY(obj.ScaleHeight, obj.ScaleMode, vbPixels)
  15.  
  16.     Pwid = Printer.ScaleX(Printer.ScaleWidth, Printer.ScaleMode, vbPixels)
  17.     Phgt = Printer.ScaleY(Printer.ScaleHeight, Printer.ScaleMode, vbPixels)
  18.  
  19.     ' This determines which dimension (X or Y) is largest, so I can make sure neither
  20.     ' dimension exceeds the printer width
  21.     If Ohgt / Owid > Phgt / Pwid Then
  22.         S = Phgt / Ohgt
  23.     Else
  24.         S = Pwid / Owid
  25.     End If
  26.  
  27.     Pwid = obj.ScaleX(Pwid * ScaleFactor, vbPixels, obj.ScaleMode) / S
  28.     Phgt = obj.ScaleY(Phgt * ScaleFactor, vbPixels, obj.ScaleMode) / S
  29.  
  30.     ' This sets the vertical and horizontal coordinates of the center of the image
  31.     ' Using the settings below, the image is printed in the center of the page
  32.     Xmid = (obj.ScaleLeft + obj.ScaleWidth / 2) * ScaleFactor
  33.     Ymid = (obj.ScaleTop + obj.ScaleHeight / 1.6) * ScaleFactor
  34.  
  35.     Printer.Scale (Xmid - Pwid / 2, Ymid - Phgt / 2)-(Xmid + Pwid / 2, Ymid + Phgt / 2)
  36.  
  37. End Sub
This prints the image in the center of the page.

Then I print a spyrograph-style pattern:

Expand|Select|Wrap|Line Numbers
  1. Sub PrintRoullette()
  2. Dim pi, r, R1, R2, i
  3.  
  4.     For i = 0 To UBound(prtR1) - 1
  5.  
  6.         R1 = prtR1(i)
  7.         R2 = prtR2(i)
  8.         r = prtR(i)
  9.  
  10.         pi = 4 * Atn(1)
  11.  
  12.         't represents time, X & Y are the coordinates of each point drawn
  13.         Dim Loop1, Loop2
  14.         Dim t, X, Y As Double
  15.         Dim Rotations As Integer
  16.  
  17.         If Int(R1 / R2) = R1 / R2 Then
  18.             Rotations = 1
  19.         Else
  20.             Rotations = Abs(R2 / 10)
  21.             If Int(R2 / 10) <> R2 / 10 Then Rotations = 10 * Rotations
  22.         End If
  23.         Rotations = Rotations + 1
  24.  
  25.         For Loop1 = 1 To Rotations
  26.  
  27.             For Loop2 = 0 To 2 * pi Step pi / (4 * 360)
  28.                 t = Loop1 * 2 * pi + Loop2
  29.                 X = (R1 + R2) * Cos(t) - (R2 + r) * Cos(((R1 + R2) / R2) * t)
  30.                 Y = (R1 + R2) * Sin(t) - (R2 + r) * Sin(((R1 + R2) / R2) * t)
  31.                 Printer.PSet (Printer.ScaleWidth / 2 + X, Printer.ScaleHeight _
  32.                   / 2 + Y), prtPen(i)
  33.             Next
  34.             DoEvents
  35.         Next
  36.     Next
  37.  
  38. End Sub
Then I issue a Printer.EndDoc command to end the job and send it to the printer.

I've tried adding pixels to the Printer.Scale statement in the SetLargePrinterScale sub:

Expand|Select|Wrap|Line Numbers
  1. Printer.Scale (Xmid - (Pwid / 2) + 300, Ymid - (Phgt / 2) + 300)-(Xmid + (Pwid / 2) + 300, Ymid + (Phgt / 2) + 300)
The printer's resolution is 300dpi, so I would expect this change to move image down and right by 1 inch - instead it moves it up and left by about 2.5 inches - I get more confused every time I print...

joe
Feb 13 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 5K+
P: 8,434
To move the X/Y position, you probably need to adjust CurrentX/CurrentY, rather than adjust the scale.
Feb 13 '07 #2

P: 6
Tried that - it works with text, but I'm using PSet() to print, so it has no effect.

joe
Feb 13 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.