Display vs. Printing

I am having an issue with the picturebox control in VB6 that has me stumped.  I am using the control on a form to draw a bell curve and plot data along the curve.  The image draws correctly in the box and is centered but when I print the form, the curve is off-center in the box and parts end up outside the picturebox.  

The calling code used to plot the curve is:

frmin.picView.Cls
frmin.picView.Scale (450, 8)-(550, 0)
DrawPlot frmin, NormalPlotArray(), False

The code that draws the curve is:

Sub DrawPlot(frmIn as form, Arry, C)
Clr = IIf(C, RGB(255, 0, 0), RGB(0, 0, 255))
frmin.picView.Line (0#, 0#)-(0#, 0#)
For j = 450 To 550
  frmin.picView.Line -(j, Arry(j)), Clr
Next j
end sub

And the plotting code is called a second time with the data in an array to plot along the curve.

In order to print, I am using the PrintForm command.

Any ideas how I can get the picturebox to print the plotted image in the center of the box?
RBourgeoisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Erick37Commented:
If you have a .wmf or .emf graphic loaded as the .Picture property of the picturebox, then this is a documented bug.

http://support.microsoft.com/support/kb/articles/Q184/6/75.ASP
0
RBourgeoisAuthor Commented:
Actually, I am not loading any graphic into the .Picture property.  I am using the line method to draw my graphic during runtime.  Any other thoughts?
0
Erick37Commented:
Perhaps use the default scale for the picturebox, then adjust the Arry() values to fit inside the picturebox.

The scale (450, 8)-(550, 0) may be throwing the printing off.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

RBourgeoisAuthor Commented:
I've played with the default scales for the picturebox instead of setting the scale programmatically with no luck.  Everytime I make a change, the image displays fine but prints off-center.
0
Erick37Commented:
Just before you print, issue these commands to set the picture as the graphic.  It should then print correctly.

frmin.picView.Picture = frmin.picView.Image
frmin.picView.Cls

To redraw the graph, clear the picture with LoadPicture("") then redraw.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mark2150Commented:
Printform doesn't support positioning of the control on the page.

You can pass the Printer device to your routine and have it render on the printer instead of on the control.

Move the .Scale command ahead of the .Cls.

Change the routine declaration from:

Sub DrawPlot(frmIn as form, Arry, C)

To:

Sub DrawPlot(frmIn as Object, Arry, C)

In your main code have:

Dim Obj as Object

Set Obj = frmin.picView
DrawPlot Obj, NormalPlotArray(), False

And it will render on that object. Change to:

Set Obj = Printer
DrawPlot Obj, NormalPlotArray(), False

and it will print.

Put the .Scale inside the subroutine to insure proper initialization.

M

0
mark2150Commented:
Oh, one more thing. Some commands are valid only for the picture box and some are only valid for the printer. Isolate them in the DrawPlot routine with:

obj.Scale (0, 0)-(8, 10.5)  '8-1/2x11 w/ 1/4" margins
'
If TypeOf obj Is Printer Then
    ' TypeOf doesn't support NOT
    obj.FontSize = 10       'Boost font size for paper
    '
Else
    obj.Show
    obj.Cls
    obj.Refresh
End If
'
' Rest of your code here...
'
If TypeOf obj Is Printer Then
    Obj.EndDoc
Else
    Obj.Refresh
End If

The .Cls method will require this as you can't .Cls a printer (nor can you set the .BackColor)...

M
0
mcriderCommented:
Since you're printing the form, take a look at this microsoft KB Article...

HOWTO: Capture and Print the Screen, a Form, or any Window
http://support.microsoft.com/support/kb/articles/Q161/2/99.ASP?LNG=ENG&SA=MSDN 
 

Using the example, you can copy the window into a picturebox and then print the picturebox... Everything should work fine...

Cheers!
0
tommy_boyCommented:
why not just editcopy (to clipboard) the picturebox - which will be printed exactly the same as the window?
0
watyCommented:
You could take a look to my Print PReview
www.geocities.com/researchtriangle/6311
0
RBourgeoisAuthor Commented:
I'll look over some of these recommendations this morning and comment on them later...thanks.
0
RBourgeoisAuthor Commented:
One of the other answers worked with far less code needed.
0
RBourgeoisAuthor Commented:
mark - the drawplot sub doesn't send the graph to the printer directly, it plots the data in the picturebox control to be printed when the user selects print from a menu item.

tommy boy - I've used the editcopy, but there are additional items on the form that need to print as well.  The graph is not the sole item in the report.  This might work, but I would prefer to keep everything within a single application rather than requiring the user to interact with multiple applications and lose some of the control over their actions.

waty - I downloaded your control and haven't gotten to checking it out yet.  One of the other suggestions did the trick for me, but I do want to take a look at the control as it may solve another issue I have with wanting to format the report to a normal size sheet of paper instead of an image of the form filling part of the page.  It would look more professional that way.

Thanks for all the suggestions guys...
0
RBourgeoisAuthor Commented:
Erick - I assumed that the solution would be something simple.  Thanks for the suggestion, it worked like a champ with minimal coding needed.
0
RBourgeoisAuthor Commented:
oops...just noticed a type-o.  In the comment to tommy boy, I meant to say I've never used the editcopy.  Just thought I ought to correct that and make it more clear.
0
mark2150Commented:
I understand that the prot is shown on screen first. When they select PRINT, THEN pass the routine the printer device for you final hardcopy. Try it!

M
0
RBourgeoisAuthor Commented:
Thanks Mark, but the solution provided by Erick37 works just fine.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.