I'm making an application for printing something out, and I thought rather than waste paper I will make a print preview thing to test it with (not a require of the final project, but i figured it shouldn't be too much work for testing purposes), so the way I thought I'd do it was using a picture box, and the .Print command. Problem is that the Picture1.CurrentX command doesn't appear todo anything, anybody know why this is? Picture1.CurrentY seems to work ok.
09-07-2003, 02:53 PM
What you want to do is target the picturebox with whatever you would target the printer object with (provided you're printing using the printer object, which you should) What i would do is write a Print() function that takes a hDC as an arguement, So that to preview you would pass the hDC of the picturebox and to do the actual print you would pass the hDC of the printer object and follow with Printer.EndDoc.
Argh, my bad, I was doing this right, I had just forgotten to take into account CurrentX only works on the first line of a multiline string. (The first line was blank, hence i didn't realise).
09-07-2003, 03:20 PM
Sounds like the hard/nonexact way to do it, but if it works for you, very well then.
How do you mean "Sounds like the hard/nonexact way to do it", heres essentially what I'm doing...
Private Sub Command1_Click()
Dim sString As String
Dim iLeft As Integer, iTop As Integer
sString = "Row one here" & vbNewLine & "Row two here" & vbNewLine & "Etc..."
iLeft = 100
iTop = 100
PrintString Picture1, sString, iLeft, iTop
Public Sub PrintString(Optional objPrint As Object, Optional sString As String, Optional iLeft As Integer, Optional iTop As Integer)
objPrint.Font.Name = "Courier New"
objPrint.Font.Size = 12
objPrint.CurrentX = iLeft
objPrint.CurrentY = iTop
...but as the string is multiline, it only aligns the first line correctly, the way I have solved this before, is to split the string with the split command, then run it through a loop printing a line at a time.
If there is a better way of doing this, I'm willing to try it, though my programming knowledge isn't superb.
09-07-2003, 04:57 PM
The Print method just isn't as prefered as using something like DrawText (API Call), though if you set the positioning up carefully as you have done there, you should be fine. I was envisioning a much more complex print sequence, with less control being exerted over the Print method.
Thanks for the suggestion, I'll certainly take a look at the DrawText API call. (I'm making a program to print guitar tab in my preffered format, i'm sure i'm going about it in a long winded manner, but if it works it'll do)
09-07-2003, 05:57 PM
It's up to you, some find it hard to understand, but I just change the
.scaleleft property to put the X = 0 point inside the page.
Each time you do a CR, CurrentX is set back to 0. So if you set your
.scaleLeft to -1440, for instance, then the 0 point of the scale is about
an inch from the left edge. So each line will line up with that point.
Just try it with a picturebox.
Dim a as string
a = "This" & vbCrLf & "is" & vbCrLf & "a" & vbCrLf & "Test"
Picture1.ScaleLeft = -(Picture1.ScaleWidth/2)
Picture1.CurrentX = 0
You should have the 4 words on 4 lines indented 1/2 way into the "page"