473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Printing Picturebox problem

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
2 3144
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
davem
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

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

Similar topics

1
by: Jos Roijakkers | last post by:
I am writing a program in Visual Studio 2005 (VB) that can print scanned images (saved as jpg-files). The printing is done by the following code: Private Sub pdoc_PrintPage(ByVal sender As...
0
by: Vincent | last post by:
Dear all, I have implemented a class to export the content of RichTextBox to image in WYSISYG mode so that line breaks on the screen are the same as exported. C# Code: public struct...
2
by: Jerry Spence1 | last post by:
The following seemed so simple in VB6 (CD1 is CommonDialogue1) CD1.CancelError = True CD1.ShowPrinter Printer.PaintPicture ActiveForm.Picture1.Picture, 720, 720 to print the image in a...
1
by: Max | last post by:
Hello, How would you print a picture box? I found sites online on printing a form and its basic controls but nothing on picture boxes. Is it possible to print a logo for example from a C# .NET...
0
by: chal | last post by:
Hi all Experts ...Hope u dong fine.. well i have a problem in my application ..here runtime i hve given facility to the user to place controls on the picture box which already have image...Now i...
2
by: deore | last post by:
Respected Sir, OS : Windows XP Professional Edition sp2 Language :visual basic 6.0 I am trying to print Picturebox which contains vertical line of length 5cm using "Printform" method.The...
1
by: VICTOR DIACONO | last post by:
I have the following problem. I am trying to print the contents of a number of Textboxes into Labels on a Picturebox. Then I wish to output the Picturebox to the screen. Ok, it is a simple...
0
by: dotnet2005 | last post by:
Hi Toall , I want to explain you clearly , I am having some panels having some controls CheckBox,ComboBox,Datagridview,Hyperlink,label,Listbox,Picturebox,RadioButt­ on ,Textbox)...
6
by: babaidebnath | last post by:
Hello all, I am presently having a problem with printing in C#. The problem is my customer provided me a pre printed paper and I need to print value into some specific positions. But problem is C#...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.