|
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 | |
Share:
Expert 8TB |
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?
| | |
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
| | Expert 8TB |
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... | | |
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..
| | Expert 8TB |
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?
| | |
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
| | Expert 8TB |
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?
| | Expert 8TB |
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.
| | |
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?
| | Expert 8TB |
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.)
| | Expert 8TB |
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. - VERSION 5.00
-
Begin VB.Form Form1
-
Caption = "Form1"
-
ClientHeight = 5340
-
ClientLeft = 60
-
ClientTop = 345
-
ClientWidth = 6030
-
LinkTopic = "Form1"
-
ScaleHeight = 5340
-
ScaleWidth = 6030
-
StartUpPosition = 3 'Windows Default
-
Begin VB.CommandButton Command2
-
Caption = "Print"
-
Height = 435
-
Left = 660
-
TabIndex = 3
-
Top = 2400
-
Width = 1275
-
End
-
Begin VB.CommandButton Command1
-
Caption = "Paste text"
-
Height = 555
-
Left = 660
-
TabIndex = 2
-
Top = 1680
-
Width = 1215
-
End
-
Begin VB.TextBox Text1
-
Height = 315
-
Left = 480
-
TabIndex = 1
-
Text = "Text1"
-
Top = 3960
-
Width = 1875
-
End
-
Begin VB.PictureBox Picture1
-
AutoRedraw = -1 'True
-
BackColor = &H00000000&
-
BorderStyle = 0 'None
-
ClipControls = 0 'False
-
ForeColor = &H0000FFFF&
-
Height = 3195
-
Left = 3240
-
ScaleHeight = 3195
-
ScaleWidth = 2415
-
TabIndex = 0
-
Top = 840
-
Width = 2415
-
End
-
End
-
Attribute VB_Name = "Form1"
-
Attribute VB_GlobalNameSpace = False
-
Attribute VB_Creatable = False
-
Attribute VB_PredeclaredId = True
-
Attribute VB_Exposed = False
-
Private Sub Command1_Click()
-
With Picture1
-
Picture1.Print Text1
-
End With
-
End Sub
-
-
Private Sub Command2_Click()
-
Printer.PaintPicture Picture1.Image, 0, 0
-
Printer.EndDoc
-
End Sub
-
-
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
Picture1.CurrentX = X
-
Picture1.CurrentY = Y
-
End Sub
| | |
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. - VERSION 5.00
-
Begin VB.Form Form1
-
Caption = "Form1"
-
ClientHeight = 5340
-
ClientLeft = 60
-
ClientTop = 345
-
ClientWidth = 6030
-
LinkTopic = "Form1"
-
ScaleHeight = 5340
-
ScaleWidth = 6030
-
StartUpPosition = 3 'Windows Default
-
Begin VB.CommandButton Command2
-
Caption = "Print"
-
Height = 435
-
Left = 660
-
TabIndex = 3
-
Top = 2400
-
Width = 1275
-
End
-
Begin VB.CommandButton Command1
-
Caption = "Paste text"
-
Height = 555
-
Left = 660
-
TabIndex = 2
-
Top = 1680
-
Width = 1215
-
End
-
Begin VB.TextBox Text1
-
Height = 315
-
Left = 480
-
TabIndex = 1
-
Text = "Text1"
-
Top = 3960
-
Width = 1875
-
End
-
Begin VB.PictureBox Picture1
-
AutoRedraw = -1 'True
-
BackColor = &H00000000&
-
BorderStyle = 0 'None
-
ClipControls = 0 'False
-
ForeColor = &H0000FFFF&
-
Height = 3195
-
Left = 3240
-
ScaleHeight = 3195
-
ScaleWidth = 2415
-
TabIndex = 0
-
Top = 840
-
Width = 2415
-
End
-
End
-
Attribute VB_Name = "Form1"
-
Attribute VB_GlobalNameSpace = False
-
Attribute VB_Creatable = False
-
Attribute VB_PredeclaredId = True
-
Attribute VB_Exposed = False
-
Private Sub Command1_Click()
-
With Picture1
-
Picture1.Print Text1
-
End With
-
End Sub
-
-
Private Sub Command2_Click()
-
Printer.PaintPicture Picture1.Image, 0, 0
-
Printer.EndDoc
-
End Sub
-
-
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
-
Picture1.CurrentX = X
-
Picture1.CurrentY = Y
-
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
| | Expert 8TB |
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.
| | Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
reply
views
Thread by Craig Malton |
last post: by
|
3 posts
views
Thread by mike_basis |
last post: by
|
3 posts
views
Thread by Paolo |
last post: by
|
2 posts
views
Thread by johnmmcparland |
last post: by
| | | | | | | | | | | | | | | |