Home All Groups Group Topic Archive Search About

PaintPicture with Printer Object in VB ver 6

Author
25 May 2005 12:56 AM
Manal
Hello

I didn't find an active classification for this question, it seems very old
topic, but I hope someone might be interested to help with it.

I am trying to use the PaintPicture with the printer object to print several
images in one page, and several text lines as well, all is specific X, Y
positions.

Using the Printer.Print method to print text, doesn't allow me to specify
the X, Y coordinates, and using the Printer.PaintPicture prints only the
first picture on the page and stops, it doesn't print more pictures even if
the page is still empty, and the height and width of the first picture is so
small (a bar code actually that I am trying to print it on a preformatted
labels sheet, with price text in specific location in the label). I tried
changing the x y coordinates after the first printing of a picture, and it
didn't work with my calculation, I tried much smaller differences, and much
bigger differences, and still not good, only prints if I use newpage method,
I can only print on the same x, y coordinates like the first time on the new
page, but I can not change the X Y coordinates even within the printer
scalewidth and scaleheight and continue printing on the same page, or on a
new page? Does that sound familiar, or was reported before?

Is that possible, or the design of the PaintPicture method allows only one
time printing in one page? And is there a way to position text printing in
the page?

I appreciate if any one can answer this for me, thank you in advance,

Manal

Author
25 May 2005 1:25 AM
MikeD
Show quote Hide quote
"Manal" <Ma***@discussions.microsoft.com> wrote in message
news:AFAC4FE5-A49B-41F8-B84A-AC3AD96BE538@microsoft.com...
>
> Using the Printer.Print method to print text, doesn't allow me to specify
> the X, Y coordinates, and using the Printer.PaintPicture prints only the
> first picture on the page and stops, it doesn't print more pictures even
> if
> the page is still empty, and the height and width of the first picture is
> so
> small (a bar code actually that I am trying to print it on a preformatted
> labels sheet, with price text in specific location in the label). I tried
> changing the x y coordinates after the first printing of a picture, and it
> didn't work with my calculation, I tried much smaller differences, and
> much
> bigger differences, and still not good, only prints if I use newpage
> method,
> I can only print on the same x, y coordinates like the first time on the
> new
> page, but I can not change the X Y coordinates even within the printer
> scalewidth and scaleheight and continue printing on the same page, or on a
> new page? Does that sound familiar, or was reported before?
>
> Is that possible, or the design of the PaintPicture method allows only one
> time printing in one page? And is there a way to position text printing in
> the page?

Look up the CurrentX and CurrentY properties.  Those let you specify the
coordinates where the next print operation should begin.

--
Mike
Microsoft MVP Visual Basic
Author
25 May 2005 1:46 AM
Manal
Thank you for answering,

The CurrentX and CurrentY properties worked actually for the printer.print
for text, which is very good, but is not working for the PaintPicture, the X,
Y coordinates parameters to this function are mandatory, and these what
specifies where to print, and I can use them to print only one image, and
can't change them later to print further images on the same page, is there a
work around this one, or am I missing something, thanks,
Author
25 May 2005 2:51 AM
Jeff Johnson [MVP: VB]
Show quote Hide quote
"Manal" <Ma***@discussions.microsoft.com> wrote in message
news:AFAC4FE5-A49B-41F8-B84A-AC3AD96BE538@microsoft.com...

> Using the Printer.Print method to print text, doesn't allow me to specify
> the X, Y coordinates, and using the Printer.PaintPicture prints only the
> first picture on the page and stops, it doesn't print more pictures even
> if
> the page is still empty, and the height and width of the first picture is
> so
> small (a bar code actually that I am trying to print it on a preformatted
> labels sheet, with price text in specific location in the label). I tried
> changing the x y coordinates after the first printing of a picture, and it
> didn't work with my calculation, I tried much smaller differences, and
> much
> bigger differences, and still not good, only prints if I use newpage
> method,
> I can only print on the same x, y coordinates like the first time on the
> new
> page, but I can not change the X Y coordinates even within the printer
> scalewidth and scaleheight and continue printing on the same page, or on a
> new page? Does that sound familiar, or was reported before?

Sample code please.
Author
25 May 2005 5:40 AM
Manal
Hi


The testing code so far is as follows:
***************************************************

Private Sub Command_Print_Click()
Printer.ScaleMode = vbTwips    ' set the printer scalemode to Twips

' there should be a loop for all barcodes read from database but I am
testing for 2 static ones for now
' first row prints the prices online on top of the bar codes
x = 1
y = 1
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "   $18"

' increment x by barcode width to print more on the same line
x = x + (MyBarCode.Picture.Width) + 10
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "   $20"
' I should be able to print more barcodes until the scalewidth of the
'page - mybarcode width is more than the current x position and then
'start the new line

'Next Line for bar codes
x = 1
y = y + 300
Printer.CurrentX = x
Printer.CurrentY = y
Printer.PaintPicture MyBarCode.Picture, x, y
' so far works fine, next bar code, doesn't print
'printing the next bar code later on line
x = x + (MyBarCode.Picture.Width) + 10
Printer.CurrentX = x
If x > Printer.ScaleWidth - MyBarCode.Picture.Width Then
    MsgBox "Printing exceeded printer width"
End If
Printer.PaintPicture MyBarCode.Picture, x, y
Printer.EndDoc

'the later lines should proceed with x initialized, y incremented by barcode
height, and keep printing prices on one raw, then barcodes on later rows till
the saceheight of the page - barcode height is more than the current y
position
' when the printer height is consumed a new page is started
End Sub


***************************************************
in the sizes I am using, I am not exceeding the printer scalewidth - barcode
width, but if we assume I do, shouldn't it try to overwrite the available
part? or it can't?

because I know I might need to overlap bar code pictures that contain empty
extra spaces that I can't get rid of, but the sample I am testing on is not,

thanks


Show quoteHide quote
"Jeff Johnson [MVP: VB]" wrote:

>
> "Manal" <Ma***@discussions.microsoft.com> wrote in message
> news:AFAC4FE5-A49B-41F8-B84A-AC3AD96BE538@microsoft.com...
>
> > Using the Printer.Print method to print text, doesn't allow me to specify
> > the X, Y coordinates, and using the Printer.PaintPicture prints only the
> > first picture on the page and stops, it doesn't print more pictures even
> > if
> > the page is still empty, and the height and width of the first picture is
> > so
> > small (a bar code actually that I am trying to print it on a preformatted
> > labels sheet, with price text in specific location in the label). I tried
> > changing the x y coordinates after the first printing of a picture, and it
> > didn't work with my calculation, I tried much smaller differences, and
> > much
> > bigger differences, and still not good, only prints if I use newpage
> > method,
> > I can only print on the same x, y coordinates like the first time on the
> > new
> > page, but I can not change the X Y coordinates even within the printer
> > scalewidth and scaleheight and continue printing on the same page, or on a
> > new page? Does that sound familiar, or was reported before?
>
> Sample code please.
>
>
>
Author
25 May 2005 7:08 AM
Manal
I am trying to print first the price, then the title of a book vertically,
then the bar code, and thats all in a specific locations on a preformatted
label, so below is an attempt to print 2 labels statically (not yet reading
from database or file), and I couldn't print another image of a bar code in
the next label, and the first image couldn't print in any different place but
the current one?

The current Code is:
***************************************************

Private Sub Command_Print_Click()
Printer.ScaleMode = vbTwips    ' set the printer scalemode to Twips

' there should be a loop for all barcodes read from database but I am
testing for 2 static ones for now
' first row prints the prices online on top of the bar codes

x = 1300
y = 800
Printer.CurrentX = x
Printer.CurrentY = y
Printer.FontSize = 6
Printer.Print "   $18"
x = 2500
y = 250
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "A"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print " "
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "G"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "i"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "f"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "t"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print " "
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "f"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "o"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "r"

' increment x by barcode width to print more on the same line
x = 3500
y = 800
Printer.CurrentX = x
Printer.CurrentY = y
Printer.FontSize = 6
Printer.Print "   $20"
x = 4700
y = 250
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "A"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print " "
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "G"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "u"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "i"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "d"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "e"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print " "
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "t"
y = y + 100
Printer.CurrentX = x
Printer.CurrentY = y
Printer.Print "o"

x = 100
y = 300
Printer.CurrentX = x
Printer.CurrentY = y
Printer.PaintPicture MyBarCode.Picture, x, y

' I should be able to print more barcodes until the scalewidth of the
'page - mybarcode width is more than the current x position and then
'start the new line

'Next Line for bar codes
' so far works fine, next bar code, doesn't print
'printing the next bar code later on line
'x = x + (MyBarCode.Picture.Width) + 10
'Printer.CurrentX = x
'If x > Printer.ScaleWidth - MyBarCode.Picture.Width Then
'    MsgBox "Printing exceeded printer width"
'End If
'Printer.PaintPicture MyBarCode.Picture, x, y
Printer.EndDoc

'the later lines should proceed with x initialized, y incremented by barcode
height, and keep printing prices on one raw, then barcodes on later rows till
the saceheight of the page - barcode height is more than the current y
position
' when the printer height is consumed a new page is started
End Sub
***************************************************
still my question: is overlapping allowed, because inside one label, I keep
going up and doen on the coordinates to print in the right place, and the
barcode image might occupy other tranparent space on the page, that I might
need to overlap,

I appreciate your help, thanks,
Show quoteHide quote
"Manal" wrote:

> Hi
>
>
> The testing code so far is as follows:
> ***************************************************
>
> Private Sub Command_Print_Click()
> Printer.ScaleMode = vbTwips    ' set the printer scalemode to Twips
>
> ' there should be a loop for all barcodes read from database but I am
> testing for 2 static ones for now
> ' first row prints the prices online on top of the bar codes
> x = 1
> y = 1
> Printer.CurrentX = x
> Printer.CurrentY = y
> Printer.Print "   $18"
>
> ' increment x by barcode width to print more on the same line
> x = x + (MyBarCode.Picture.Width) + 10
> Printer.CurrentX = x
> Printer.CurrentY = y
> Printer.Print "   $20"
> ' I should be able to print more barcodes until the scalewidth of the
> 'page - mybarcode width is more than the current x position and then
> 'start the new line
>
> 'Next Line for bar codes
> x = 1
> y = y + 300
> Printer.CurrentX = x
> Printer.CurrentY = y
> Printer.PaintPicture MyBarCode.Picture, x, y
> ' so far works fine, next bar code, doesn't print
> 'printing the next bar code later on line
> x = x + (MyBarCode.Picture.Width) + 10
> Printer.CurrentX = x
> If x > Printer.ScaleWidth - MyBarCode.Picture.Width Then
>     MsgBox "Printing exceeded printer width"
> End If
> Printer.PaintPicture MyBarCode.Picture, x, y
> Printer.EndDoc
>
> 'the later lines should proceed with x initialized, y incremented by barcode
> height, and keep printing prices on one raw, then barcodes on later rows till
> the saceheight of the page - barcode height is more than the current y
> position
> ' when the printer height is consumed a new page is started
> End Sub
>
>
> ***************************************************
> in the sizes I am using, I am not exceeding the printer scalewidth - barcode
> width, but if we assume I do, shouldn't it try to overwrite the available
> part? or it can't?
>
> because I know I might need to overlap bar code pictures that contain empty
> extra spaces that I can't get rid of, but the sample I am testing on is not,
>
> thanks
>
>
> "Jeff Johnson [MVP: VB]" wrote:
>
> >
> > "Manal" <Ma***@discussions.microsoft.com> wrote in message
> > news:AFAC4FE5-A49B-41F8-B84A-AC3AD96BE538@microsoft.com...
> >
> > > Using the Printer.Print method to print text, doesn't allow me to specify
> > > the X, Y coordinates, and using the Printer.PaintPicture prints only the
> > > first picture on the page and stops, it doesn't print more pictures even
> > > if
> > > the page is still empty, and the height and width of the first picture is
> > > so
> > > small (a bar code actually that I am trying to print it on a preformatted
> > > labels sheet, with price text in specific location in the label). I tried
> > > changing the x y coordinates after the first printing of a picture, and it
> > > didn't work with my calculation, I tried much smaller differences, and
> > > much
> > > bigger differences, and still not good, only prints if I use newpage
> > > method,
> > > I can only print on the same x, y coordinates like the first time on the
> > > new
> > > page, but I can not change the X Y coordinates even within the printer
> > > scalewidth and scaleheight and continue printing on the same page, or on a
> > > new page? Does that sound familiar, or was reported before?
> >
> > Sample code please.
> >
> >
> >
Author
25 May 2005 12:36 PM
Larry Serflaten
"Manal" <Ma***@discussions.microsoft.com> wrote
> I am trying to print first the price, then the title of a book vertically,
> then the bar code, and thats all in a specific locations on a preformatted
> label, so below is an attempt to print 2 labels statically (not yet reading
> from database or file), and I couldn't print another image of a bar code in
> the next label, and the first image couldn't print in any different place but
> the current one?


Try to treat a label as a single object.  Then plan to provide a routine to
print a single lable, passing in as parameters all it needs to know to print
out the information.  For example, you would probably need to pass in the
X and Y coordinates where you want the lable, and probably some text,
and whatever else....

That lets you work on positioning stuff inside the label, all in one routine,
where other code that calls that routine can decide where the labels need
to go, and what they contain.

For an example, add a picturebox to a new form and paste in the code below.
When you run the program, you should see it print out 6 lables....

HTH
LFS


Private Sub Form_Load()
Dim i, r
  ' Fake barcode
  Randomize
  With Picture1
    .BackColor = vbWhite
    .Move 0, 0, 1830, 630
    .AutoRedraw = True
  End With
  For i = 0 To 60
    r = Int(Rnd * 26) * 60 + 90
    r = r + Int(Rnd * 2) * 15
    Picture1.Line (r, 90)-Step(0, 390), vbBlack
  Next i
  Picture1.Line (0, 0)-(1755, 555), vbRed, B

  ' Print lables
  r = Printer.ScaleWidth \ 4
  For i = 1 To 3
    PrintLable i * r, 120, "This is label " & CStr(i)
    PrintLable i * r, 1500, "This is label " & CStr(i + 3)
  Next
  Printer.EndDoc
End Sub


Private Sub PrintLable(X&, Y&, Text$)
  Printer.Line (X, Y)-Step(2200, 1100), vbBlue, B
  Printer.PSet (X + 120, Y + 120), vbWhite
  Printer.Print Text
  Printer.PaintPicture Picture1.Image, X + 120, Y + 390
End Sub
Author
26 May 2005 2:19 AM
Manal
Thank you for replying

sorry for sending earlier a messy code like that, however, your code works
only for the fake image you sent, and for the barcode image OCX I am having
(Morovia Bar Code ActiveX), it doesn't work,

I think the reason is in the picture size of the barcode. is PaintPicture if
given overlapping X and Y coordinates, like if the first time we print on X =
1 and Y = 1 for an image of size 100 and 300, and the next time I print on X
= 1 and Y = 150 (next row),  or X = 75 and Y = 1 (next column) with image of
the same size, will it be able to overlap printing, and show all images, the
next being printed in the white space of the previous and so on

because in this activeX the bar code is printed in a very small area within
its picture size, and so far, it doesn't seem that I can dynamically change
the picture size without shrinking the barcode size as well (still working in
this direction as well)

I appreciate your help, thanks,
Author
26 May 2005 12:08 PM
Larry Serflaten
"Manal" <Ma***@discussions.microsoft.com> wrote

> I think the reason is in the picture size of the barcode. is PaintPicture if
> given overlapping X and Y coordinates, like if the first time we print on X =
> 1 and Y = 1 for an image of size 100 and 300, and the next time I print on X
> = 1 and Y = 150 (next row),  or X = 75 and Y = 1 (next column) with image of
> the same size, will it be able to overlap printing, and show all images, the
> next being printed in the white space of the previous and so on

If that is a question, then yes, if you overlap images, they overlap in the
printout.  Even if you overlap with a white color, it is still a color and will
take precedense over anything that was there.

See if this example helps you to sort it out.  Add a picturebox to a new
form and paste in the code.  Note how PaintPicture was used to crop the
icon to just use a part of the picture (just like you need to only grab the
barcode image out of a larger picture), and then see how allowing it to
paint again overlaps whatever was there....

HTH
LFS

Private Sub Form_Load()
   Picture1.Move 0, 0, 930, 930
   Picture1.BackColor = vbYellow
   Picture1.AutoRedraw = True
   Picture1.Picture = Me.Icon
   Picture1.Picture = Picture1.Image
   Me.AutoRedraw = True

   ' Grab just the section you need 
   Me.PaintPicture Picture1, 2000, 2000, 3000, 3000, 60, 60, 270, 270

   ' Note how the first image is overlapped
   Me.PaintPicture Picture1, 1800, 3600
End Sub



Show quoteHide quote
>
> because in this activeX the bar code is printed in a very small area within
> its picture size, and so far, it doesn't seem that I can dynamically change
> the picture size without shrinking the barcode size as well (still working in
> this direction as well)
>
> I appreciate your help, thanks,
>