Results 1 to 4 of 4

Thread: [RESOLVED] In VB6, PrintForm Method does not print contents of picture box on form

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2016
    Posts
    13

    Resolved [RESOLVED] In VB6, PrintForm Method does not print contents of picture box on form

    Hello,

    I have a form and it contains a PictureBox control. AutoRedraw is set to True for both the form and the PictureBox. In the PictureBox I have done some drawing using the Line method.

    I want to print the form and the graphics that appear in the PictureBox.
    When I use the PrintForm method (Form1.PrintForm) the printed copy shows the form and the border of the PictureBox, but none of the graphics that were drawn in the PictureBox.

    Can anyone suggest why the graphics aren't printing? Thank you.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: In VB6, PrintForm Method does not print contents of picture box on form

    I just did a quick test with a Picturebox and a button on the form. The picturebox's Autoredraw was set to True in the IDE, but not the form.
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
      Form1.PrintForm
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      Static lx As Single, ly As Single
      If Button = vbLeftButton Then
        Picture1.Line (lx, ly)-(X, Y)
      End If
      lx = X: ly = Y
    End Sub
    I scribble a little bit in the picturebox and then printed and thought it was working as is. But then I noticed the drawing inside the picturebox was shifted.
    The drawing of the AutoRedraw buffer of the picturebox seems to draw relative to the form, not the picturebox, so depending on where your picturebox is and perhaps the scale of the form relative to the picturebox you may not see the drawing as it will be drawn outside the bounds of the picturebox.

    So I added a line of code to have the Picture object of the picturebox reference the Image object of the picturebox (the Image object is what is drawn into when you have AutoRedraw set), so the Picture is now the same as the Image. That seems to print fine.
    Code:
    Private Sub Command1_Click()
      Picture1.Picture = Picture1.Image
      Form1.PrintForm
    End Sub
    Last edited by passel; Sep 20th, 2017 at 08:43 AM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2016
    Posts
    13

    Re: In VB6, PrintForm Method does not print contents of picture box on form

    Thank you! It works perfectly. Thank you for taking the time to figure out a solution. It is greatly appreciated!

  4. #4
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: [RESOLVED] In VB6, PrintForm Method does not print contents of picture box on for

    It may not be a problem using .printform for what you are doing here.
    If there is other stuff on your form that is also important, you will find that .printform is not as sharp, nor as accurate as you desire.
    When you reach that stage in the future (using .printform) yell out, and we can explore alternatives.

    Rob
    PS I do not use .printform these days.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width