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

Printing Picturebox problem

P: 2
Hi,
I am writing a program in VB6 where an image is loaded into a picture box if I print this image it is exactly where I expect it to be.

The problem is I need to be able to draw lines on the image in the picture box.

This works fine on the screen but when I then print the image has moved diagonally towards the top left corner of the picturebox.

I am sure the problem is with the line drawing code but can not work out why it is moving the image when printing.

the drawing code is below :-
Expand|Select|Wrap|Line Numbers
  1. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.  
  3.     'Releases last line if right mouse button is pushed
  4.     If Button = 2 Then
  5.         'Erases current Line
  6.         Picture1.Line (X1, Y1)-(X2, Y2)
  7.         'Reset line vaiables
  8.         X2 = 0
  9.         Y2 = 0
  10.         LineOn = False
  11.         Exit Sub
  12.     End If
  13.     'If the LineOn Flag is true
  14.     If LineOn Then
  15.         'Erase the Stretch Line
  16.         Picture1.Line (X1, Y1)-(X2, Y2)
  17.         'Turn inverted draw off
  18.         Picture1.DrawMode = 13
  19.  
  20.             X2 = X
  21.             Y2 = Y
  22.  
  23.         'Draw the final line
  24.         Picture1.Line (X1, Y1)-(X2, Y2), RGB(0, 255, 0)
  25.         'Set new start line points
  26.  
  27.             X1 = X2
  28.             Y1 = Y2
  29.  
  30.             X1 = X
  31.             Y1 = Y
  32.  
  33.  
  34.         If LineOn <> 1 Then
  35.             X2 = 0
  36.             Y2 = 0
  37.             LineOn = False
  38.             Exit Sub
  39.         End If
  40.     Else
  41.         'The line has not been drawn yet
  42.  
  43.             X1 = X: Y1 = Y
  44.  
  45.         'Set end values
  46.         X2 = X
  47.         Y2 = Y
  48.         LineOn = True
  49.     End If
  50.     Picture1.DrawMode = 6
  51.     Picture1.DrawStyle = 6
  52.     X3 = X: Y3 = Y: X4 = X: Y = Y4
  53. End Sub
  54.  
  55. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  56.     'Draw the stretch or rubberband line
  57.     If LineOn Then
  58.         Picture1.AutoRedraw = True
  59.         Picture1.Line (X1, Y1)-(X2, Y2)
  60.         X2 = X
  61.         Y2 = Y
  62.         Picture1.Line (X1, Y1)-(X, Y)
  63.  
  64.  
  65.     End If
  66. End Sub 
I hope someone can help with this as it is driving me mad

Dave
Apr 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: 31
I have thoroughly analysed your code, and have fixed it up for you; however, I am not sure if it will fix your printing problem. Try checking the print settings before printing (i.e. alignment, orientation, margins, etc.)

Declarations
Expand|Select|Wrap|Line Numbers
  1. Private LineOn As Boolean
  2. Private X1 As Long, Y1 As Long, X2 As Long, Y2 As Long
General Code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.  
  3.     Select Case Button
  4.     Case 1 'Left mouse button (draw)
  5.         If LineOn Then
  6.             'Complete the current line
  7.             Picture1.DrawMode = 13
  8.             Picture1.Line (X1, Y1)-(X, Y), RGB(0, 255, 0)
  9.             LineOn = False
  10.         Else
  11.             'Prepare to draw line
  12.             X1 = X
  13.             Y1 = Y
  14.             X2 = X
  15.             Y2 = Y
  16.             LineOn = True
  17.         End If
  18.     Case 2 'Right mouse button (cancel)
  19.         If LineOn Then
  20.             'Erase line if one is being constructed
  21.             Picture1.Line (X1, Y1)-(X, Y)
  22.             LineOn = False
  23.         End If
  24.     End Select
  25.     Picture1.DrawMode = 6
  26.     Picture1.DrawStyle = 6
  27.  
  28. End Sub
  29.  
  30. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  31.  
  32.     If LineOn Then
  33.         Picture1.AutoRedraw = True
  34.         'Erase the previous line created by last mouse move
  35.         Picture1.Line (X1, Y1)-(X2, Y2)
  36.         X2 = X
  37.         Y2 = Y
  38.         'Draw the stretch or rubberband line
  39.         Picture1.Line (X1, Y1)-(X, Y)
  40.     End If
  41.  
  42. End Sub
  43.  
Apr 4 '07 #2

P: 2
Thanks for that it solved the right clicking to clear the line if you choose not to continue drawing, but still have the printing problem. I am new to this and it does not make sence to me that I can load different images from a drop down combo box and they load exactly in the picture box and just using the print form command will print it exactly where it should be, the form fits exactly the width of an A4 sheet of paper.
Draw even the shortest line and it prints the form ok with the picture box where it should be but the picture and lines have moved up and to the left obscuring the picture as though it has slipped behind the form.
I think I am going to have to try writing a full print command but are not sure that it will solve it.

Dave
Apr 11 '07 #3

Post your reply

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