473,770 Members | 6,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing Picturebox problem

2 New Member
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 3166
tristanlbailey
31 New Member
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 New Member
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
1221
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 Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument.PrintPage Dim i As Integer Dim intPrintAreaHeight, intPrintAreaWidth, marginLeft, marginTop As Int32 With PrintDocument.DefaultPageSettings
0
11159
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 STRUCT_RECT
2
10795
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 picturebox. I have spent hours Googling to try and fathom out how to do it in VB.Net (2005). Surely it doesn't take all the code I've seen?
1
7011
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 application? Max
0
963
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 want to take a print of all those contents or we can say controls placed in the picturebox....sa can anybody help me or tell me what should i do??any code sample plz?? waiting 4 ur reply chal
2
1359
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 problem is output on page is vertical line with length 4cm.
1
2386
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 matter of assigning the value of the Textbox to a Label in the Picturebox. But VB.NET doesn't seem to support a Print method for the Picturebox. How do I output the Picturebox (complete with its contents) to screen or the printer?
0
1170
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) &(Oval,Line,Rectangle ). with .BorderStyle = BorderStyle.FixedSingle . All these things are generating at runtime
6
10269
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# for its generic autofit to page nature dont let me doing this. Every time it is decreasing whole page's size and also altering my value position into some specific ratio. Can anyone tell me how can I come over that problem. This is my code
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10225
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10001
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8880
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.