Link to home
Start Free TrialLog in
Avatar of RBourgeois
RBourgeois

asked on

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?
Avatar of Erick37
Erick37
Flag of United States of America image

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
Avatar of RBourgeois
RBourgeois

ASKER

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?
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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
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!
why not just editcopy (to clipboard) the picturebox - which will be printed exactly the same as the window?
You could take a look to my Print PReview
www.geocities.com/researchtriangle/6311
I'll look over some of these recommendations this morning and comment on them later...thanks.
One of the other answers worked with far less code needed.
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...
Erick - I assumed that the solution would be something simple.  Thanks for the suggestion, it worked like a champ with minimal coding needed.
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.
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
Thanks Mark, but the solution provided by Erick37 works just fine.