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

Urgent help required ASAP Please!!!

P: 7
Hi,

I have recently added some code to my form in regards to resizing an image on Print. I have an image that does print correctly after its been resized, howver i'm needing to use it as a backgound image which will have variable text written in front of it. I am having trouble geting labels and text boxes to print, along with the inlarged image that is printing. The labels and text boxes need to appear infront of the image.

And where do I place the necessary code?

Please help!! Urgently needed!

My code currently looks like this:


Private Sub cmdPrint_Click()
Printer.PaperSize = 3

'Print the image loaded in Picture1 (double size)
PrintImage Image1.Picture, , , 1#

End Sub
------------------------------

'Print the Picture contained in a PictureBox or a Form
Public Sub PrintImage(p As IPictureDisp, Optional ByVal x, Optional ByVal y, Optional ByVal resize)

If IsMissing(x) Then x = Printer.CurrentX
If IsMissing(y) Then y = Printer.CurrentY
If IsMissing(resize) Then resize = 1
Printer.PaintPicture p, x, y, p.Width * resize, p.Height * resize

End Sub
Nov 27 '06 #1
Share this Question
Share on Google+
13 Replies


Expert 5K+
P: 8,434
I think you will need to print the various controls separately. It seems likely that the PrintPicture command would only send the contents of the .Picture (or maybe .Image) property, not other controls that are shown over the top of it.

Here's an idea - just as a quick workaround, could you duplicate the picturebox and associated labels etc. onto another form, then use thatform.PrintForm?
Nov 28 '06 #2

P: 7
I think you will need to print the various controls separately. It seems likely that the PrintPicture command would only send the contents of the .Picture (or maybe .Image) property, not other controls that are shown over the top of it.

Here's an idea - just as a quick workaround, could you duplicate the picturebox and associated labels etc. onto another form, then use thatform.PrintForm?


The only issue with doing this is that it only prints what can be seen physically on the screen.. the image i'm using needs to be resized to print out exactly A4 in height and width.

Me.PrintForm command only prints what can be seen on the screen.

Any other options i can try??

Much Appreciated
Nov 28 '06 #3

Expert 5K+
P: 8,434
The only issue with doing this is that it only prints what can be seen physically on the screen.. the image i'm using needs to be resized to print out exactly A4 in height and width.
Me.PrintForm command only prints what can be seen on the screen.
Any other options i can try??
Try these...
Nov 28 '06 #4

P: 7
Try these...

I've looked at these 2 examples however they don't really solve my issue..

This is my exact problem:

I have an image which is nothing but a black rectangle (210mm x 297mm) in size. It is to be used as a background for what i'm trying to print.

I am printing it on A3 size paper. Infront of this black rectangle, i require to print the text from either text boxes or labels, situated infront of the black rectangle.

I can do this when the image isn't bigger than the screen. Ie. i can do it for A8, A6, and A5 sized images.

I have attached a copy of one of the smaller images, which i require the exact output to be printed in A4 size.

Thanks for your help again..
Attached Images
File Type: bmp Ticket.bmp (31.3 KB, 149 views)
Nov 28 '06 #5

Expert 5K+
P: 8,434
Sorry, although I do have some fairly extensive experience with printing forms and so on in VB6 (or earlier), it was probably something like 10 years ago. With luck, maybe someone else can help.

I'm just leaving work, but will try to do some research on this when I get home.

By the way, what did you mean exactly by "I can do this when the image isn't bigger than the screen"? How are you doing it now?
Nov 28 '06 #6

P: 7
Sorry, although I do have some fairly extensive experience with printing forms and so on in VB6 (or earlier), it was probably something like 10 years ago. With luck, maybe someone else can help.

I'm just leaving work, but will try to do some research on this when I get home.

By the way, what did you mean exactly by "I can do this when the image isn't bigger than the screen"? How are you doing it now?

Private Sub cmdPrint_Click()
Printer.PaperSize = 3
Dim pcoControl As Control
Me.BackColor = vbWhite
Me.ForeColor = vbWhite

For Each pcoControl In Me.Controls
If TypeOf pcoControl Is TextBox Then
pcoControl.BackColor = vbBlack
pcoControl.BorderStyle = 0
ElseIf TypeOf pcoControl Is CommandButton Then
pcoControl.Visible = False
End If
Next pcoControl
Me.PrintForm
'** Then set all the properties back to their initial values by reversing the above
'** code.
End Sub
Nov 28 '06 #7

Expert 5K+
P: 8,434
Ok, let me see whether I've got the situation straight. You have tried two methods so far:
  • Printer.PaintPicture
    Prints the picture OK, but not the things you want overlaid.
  • Me.PrintForm
    Works, but the size is limited.
Does this sound right?
Nov 28 '06 #8

Expert 5K+
P: 8,434
One more questiuon - have you tried printing the text and other stuff (lines, boxes or whatever) onto the picture box, then sending the picture to the printer using your original method? If so, what was the result?

Note that for this to work, I expect you'd need to have AutoRedraw = True to create persistent graphics, otherwise it would just use the original picture.
Nov 28 '06 #9

P: 7
One more questiuon - have you tried printing the text and other stuff (lines, boxes or whatever) onto the picture box, then sending the picture to the printer using your original method? If so, what was the result?

Note that for this to work, I expect you'd need to have AutoRedraw = True to create persistent graphics, otherwise it would just use the original picture.

In answer to your first question, yes this is correct! The answer to your second question, well the text to be displayed will changed according to an if statement, so simply pasting it on the picture will not help.

???

Do you know of any companies or individuals that can come on site to see if they can code what i require?
Nov 29 '06 #10

Expert 5K+
P: 8,434
In answer to your first question, yes this is correct! The answer to your second question, well the text to be displayed will changed according to an if statement, so simply pasting it on the picture will not help.
What I meant was that you should be able to take your text and use the .Print method to place it onto the picture before sending it to the printer. This is where the AutoRedraw property becomes important, of course.

Do you know of any companies or individuals that can come on site to see if they can code what i require?
I don't even know what country you're in. :)

I've just started my lunch break, so I'll see whether I can come up with any further leads for you. But just checking out any tutorials on VB printing might help, as in theory this should be fairly straightforward. (Of course, should doesn't always help.)
Nov 29 '06 #11

Expert 5K+
P: 8,434
I've been doing a bit of playing over lunch. This sample form I've been mucking about with allows me to type text into a textbox, click a button to paste it onto the picture box (clicking on the picture box selects the position for the text) then click another button to print that picture. (You can paste as mnay pieces of text as many times as you like, of course).

I realise this is pretty basic stuff (no pun intended). But by playing with properties of the picture box such as the font and so on, I don't see why this approach wouldn't allow your code to produce whatever you want.

If you'd like to use this form, just open a .FRM file in Notepad and paste this into it, completely replacing the contents.

At the very least, this should give us an idea of whether I'm completely off the track.
Expand|Select|Wrap|Line Numbers
  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   5340
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6030
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   5340
  10.    ScaleWidth      =   6030
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Command2 
  13.       Caption         =   "Print"
  14.       Height          =   435
  15.       Left            =   660
  16.       TabIndex        =   3
  17.       Top             =   2400
  18.       Width           =   1275
  19.    End
  20.    Begin VB.CommandButton Command1 
  21.       Caption         =   "Paste text"
  22.       Height          =   555
  23.       Left            =   660
  24.       TabIndex        =   2
  25.       Top             =   1680
  26.       Width           =   1215
  27.    End
  28.    Begin VB.TextBox Text1 
  29.       Height          =   315
  30.       Left            =   480
  31.       TabIndex        =   1
  32.       Text            =   "Text1"
  33.       Top             =   3960
  34.       Width           =   1875
  35.    End
  36.    Begin VB.PictureBox Picture1 
  37.       AutoRedraw      =   -1  'True
  38.       BackColor       =   &H00000000&
  39.       BorderStyle     =   0  'None
  40.       ClipControls    =   0   'False
  41.       ForeColor       =   &H0000FFFF&
  42.       Height          =   3195
  43.       Left            =   3240
  44.       ScaleHeight     =   3195
  45.       ScaleWidth      =   2415
  46.       TabIndex        =   0
  47.       Top             =   840
  48.       Width           =   2415
  49.    End
  50. End
  51. Attribute VB_Name = "Form1"
  52. Attribute VB_GlobalNameSpace = False
  53. Attribute VB_Creatable = False
  54. Attribute VB_PredeclaredId = True
  55. Attribute VB_Exposed = False
  56. Private Sub Command1_Click()
  57.   With Picture1
  58.     Picture1.Print Text1
  59.   End With
  60. End Sub
  61.  
  62. Private Sub Command2_Click()
  63.   Printer.PaintPicture Picture1.Image, 0, 0
  64.   Printer.EndDoc
  65. End Sub
  66.  
  67. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  68.   Picture1.CurrentX = X
  69.   Picture1.CurrentY = Y
  70. End Sub
Nov 29 '06 #12

P: 7
I've been doing a bit of playing over lunch. This sample form I've been mucking about with allows me to type text into a textbox, click a button to paste it onto the picture box (clicking on the picture box selects the position for the text) then click another button to print that picture. (You can paste as mnay pieces of text as many times as you like, of course).

I realise this is pretty basic stuff (no pun intended). But by playing with properties of the picture box such as the font and so on, I don't see why this approach wouldn't allow your code to produce whatever you want.

If you'd like to use this form, just open a .FRM file in Notepad and paste this into it, completely replacing the contents.

At the very least, this should give us an idea of whether I'm completely off the track.
Expand|Select|Wrap|Line Numbers
  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   5340
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   6030
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   5340
  10.    ScaleWidth      =   6030
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Command2 
  13.       Caption         =   "Print"
  14.       Height          =   435
  15.       Left            =   660
  16.       TabIndex        =   3
  17.       Top             =   2400
  18.       Width           =   1275
  19.    End
  20.    Begin VB.CommandButton Command1 
  21.       Caption         =   "Paste text"
  22.       Height          =   555
  23.       Left            =   660
  24.       TabIndex        =   2
  25.       Top             =   1680
  26.       Width           =   1215
  27.    End
  28.    Begin VB.TextBox Text1 
  29.       Height          =   315
  30.       Left            =   480
  31.       TabIndex        =   1
  32.       Text            =   "Text1"
  33.       Top             =   3960
  34.       Width           =   1875
  35.    End
  36.    Begin VB.PictureBox Picture1 
  37.       AutoRedraw      =   -1  'True
  38.       BackColor       =   &H00000000&
  39.       BorderStyle     =   0  'None
  40.       ClipControls    =   0   'False
  41.       ForeColor       =   &H0000FFFF&
  42.       Height          =   3195
  43.       Left            =   3240
  44.       ScaleHeight     =   3195
  45.       ScaleWidth      =   2415
  46.       TabIndex        =   0
  47.       Top             =   840
  48.       Width           =   2415
  49.    End
  50. End
  51. Attribute VB_Name = "Form1"
  52. Attribute VB_GlobalNameSpace = False
  53. Attribute VB_Creatable = False
  54. Attribute VB_PredeclaredId = True
  55. Attribute VB_Exposed = False
  56. Private Sub Command1_Click()
  57.   With Picture1
  58.     Picture1.Print Text1
  59.   End With
  60. End Sub
  61.  
  62. Private Sub Command2_Click()
  63.   Printer.PaintPicture Picture1.Image, 0, 0
  64.   Printer.EndDoc
  65. End Sub
  66.  
  67. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  68.   Picture1.CurrentX = X
  69.   Picture1.CurrentY = Y
  70. End Sub

Really appreciate the time and effort you are making on this for me..

Just wandering if it were possible for you to send me the Form Layout of the above code.. I'm not the most experienced programmer..

Also some of the text from the code when pasted into VB, becomes highlighted in bright red.. ie. not sure whether it will compile or not on run..

code in red is below:
Begin VB.Form Form1
Begin VB.CommandButton Command2
Begin VB.CommandButton Command1
Begin VB.TextBox Text1
Begin VB.PictureBox Picture1
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Everything else seems to look asthough it will compose
Nov 29 '06 #13

Expert 5K+
P: 8,434
Try this.
  • Paste the text I posted into a text file, using Notepad or whatever
  • Save it with the extension .Frm instead of .Txt
  • Create a new project in VB6, with no forms or modules etc.
  • Use "Add" (Ctrl-D I think) to add the "form" we just saved
  • Set this form as the startup form
  • Run
You see, the text I posted is what VB actually saves in the Frm file. I did it that way so there was no problem over attachments, and blocked uploads/downloads and so on.
Nov 30 '06 #14

Post your reply

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