Saving text printed (.print) on a form?

Posted on 2002-06-28
Last Modified: 2010-05-02
I made a program whose output is in another form, maximized and no bordered so it's full screen. The output is made using the form.print function using different forecolors for the form.
What I need to do is to be able to either:
 1. Print the text into a picture box which will hold it the way the form displayed the text, it will not crop it and will be able to be saved.
 2. find some other way to turn the colored text into an image which could be bigger than the screen resolution(not using autodraw)

If you need any additional details ask freely
thanks alot in advance
Question by:lan_nur
  • 4
  • 4
  • 2
  • +2
LVL 18

Expert Comment

ID: 7117698
why don't you just use a textbox or a label?

Expert Comment

ID: 7117726
If I'm understanding your problem...
What I do in that case is as follows...

Dim outputObj as Object
dim previewMode as boolean

' set previewMode as appropriate

'you may also like to set different scaleModes for each possible output context so that the display doesn't fall off the screen/page

if previewMode then
  set outputObj = myForm (thescreen object you are using)
  set outputObj = Printer  (or other target context)

' do my printing stuff

' finally
if outputObj = printer then outputobj.enddoc


Author Comment

ID: 7118314
What I meant was:
I have a form\picture box which I print into using the .Print method which prints simple text. All I want to do is to be able to handle this picture as if it was a regular picture, ie: To be able to print into it even if it's outside of the screen boundries.

Mccoop, your post would help if I were using a regular picture box without using .Point(x,y) to get pixel colors (which forces the picture to be in screen boundries) and without using the .Print method.
Is it possible to directly write to a graphic file?

Hope this helps.
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


Expert Comment

ID: 7118450
You can make a picturebox larger than the screen area - and I have certainly drawn into one like that (although not with the point() function).  I also used the print() function to draw to the picturebos...

Although I did have issues and had to manipulate the picturebox's .AutoRedraw property.

Does the point() function not work outside the screen dimensions... ?  (Never tried that)

You could do it with very short line() calls... (well it's not nice - but I haven't had problems with the line() function being persistent outside screen area)

But I still had to work with the .autoredraw setting.

My application has a scrolling picturebox - which can be many times the screen area, and I draw text, lines, and even place activeX controls into it.

These are all persistent when managed properly - although I agree that it is one of the areas most dependent on video cards and drivers.

Some machines don't handle it at all well (lines and text get forgotten when scrolling etc) , others require a reboot after the app is installed, while the majority work straight off.


Expert Comment

ID: 7118457
Sorry - back to my earlier post...

It requires a substantial rewrite, but if you plan your scaling correctly, changing the target context does work - and allows you to 'see' what you're going to get (+/- 1 twip)

Then you can also manipulate the numbers if you want to print the form into into a single page, or tile across multiple sheets of paper to keep the sixe of objects etc

Author Comment

ID: 7118859
All the years I've been working with VB, I didn't quite get the scaling thing and Twips and making an application work on all resolutions. Can you maybe explain how to scale the picture? Perhaps that's the answer.
And how did you make the picture scroll? That may be the answer too.

Expert Comment

ID: 7119169
 You may use a large hidden picture box with autoredraw property, so that you print the text in both of them. And when you want to save or print the text, you can use the hidden picturebox.
  In case this solution didn't satisfy you, could you tell us why you don't want to use autodraw? It will save a lot of time and effort.


Expert Comment

ID: 7119365
To make a scrolling picturebox, you need to place one picturebox (your drawing target) inside another (the container.

If you use scrollbars, then these would also be placed in the container (a tthe bottoma nd right edges.

You need to place the target and scroll bars programmatically (.move) if the container is going to be resizable.

Once the positioning is done (assuming the target is larger than the container) - you need to develop a relationship between the scrollbars and the target-to-container width & height,

By moving the top and left values of the target, you effectively move the vviewport into the target window.

If the target-tocontainer relationship is not constant (i.e window sizes may be different) The scaling of the scrollbars is also a variable, thus you need to manage  the min & max values in realtime.

Ths sounds complicated - but is not really, and once you've done it - it all makes sense and is easy to manipulate.

Here is a KB article:;en-us;Q186429

Expert Comment

ID: 7120152
i dont quete understand what you are trying to do
but try this:
start a new exe project
form1 is created
make form1 a mdi-child
make autoredraw true
give form1 a single line border
give form1 no control box and no caption
the code in form1:

Private Sub Form_Load()
    Me.Move 90, 90, Screen.Width * 5, Screen.Height * 5
End Sub

add an mdi form to the project

now run the project and you will have a scrollable form that's as wide as 5 times the screen and as height as 5 times the screen

with this form you can do anything you can do with a 'normal' form
even reading the pixel color of a pixel that is not visible

and if you dont want the autoredraw=true,just place all the graphics methods in the paint event(but then you wont be able to read a hidden pixel)


Author Comment

ID: 7120543
I never said I didn't want to use Autodraw, it helps me alot.
I'll try the MDI Child later, but what I need to do is save the picture that was printed over. Even with autodraw it doesn't save it with the text.
Anyone advice?

Accepted Solution

egsemsem earned 350 total points
ID: 7120573
Do u use:
SavePicture Picture1.Image, "c:\tmp.bmp"
SavePicture Picture1.Picture, "c:\tmp.bmp"

the first one should save the picture with the text drawn over it.


Expert Comment

ID: 7120659
i dont want to sound patronising, but why do you want to save an image of a form/picturebox,if at anytime you can recreate what you have done
if by chance it is to send that image to the printer, you are better of using the system mcoop gave you
that way it does not matter if you are printing to a form or picturebox or the printer, the output will be exactly the same
if you send the saved image of the form/picturebox to the printer the quality will be no good, it will be screen quality
if you use mcoop's method the printer output will be the best the printer can do

Author Comment

ID: 7122950
In the end egsemsem's post about the image/picture solved the saving problem and pierrecampe's solution with the mdi child solved the size matter.
so thanks.
I'll give the points to egsemsem and pierre, if u want ill post another question so u get points too.

mcoop, thanks ALOT for your help too!

Thank you all

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question