Image of Navigational Panel mapped to Contents / Home / Search VB Printing Question
Tech Support Question

Image of Line Break

Q. I was researching a printing problem I'm having in 16-bit VB 4.0 and saw your reply to a printing question and thought you might be able to help me out. I've coded a 16-bit VB 4.0 form that displays 7 graphs side by side like this:

  graph1 graph2 graph3 graph4 graph5 graph6 graph7

To code this, I draw the first graph by customizing the screen coordinate system so that 0,0 is in the lower left of the graph, then I draw the first graph. Then I change the screen coordinate system so that 0,0 is in the lower left of the second graph, draw the graph, etc. By now you can probably guess my problem - this looks great on the screen, but when I print the graph, it looks like all the graphs draw on top of each other.

So I guess the printer's coordinates don't work like the screen coordinates??? I think I need to change my approach. Where can I find out more information on the best technique to print graphics in VB? I've read the graphics printing section of the VB manual but I think I'm still missing a few tricks. Any ideas or techniques you can suggest would be greatly appreciated.

TIA,

From: John Mankowski
Email: mankow@cftnet.com

A. John, hopefully I can help you out. Sounds like you have written some pretty cool graphing code, controlling screen coordinates and all. It's a shame that the printer object works differently. Basically the printer is not quite so flexible, so you need to apply some tricks to get everything to print where you want it.

The approach I would take to doing this is to use a pair of offsets to allow me to control the positioning of each graph on the printed page. So, everytime you draw a point or line on the printer you add the offsets. For the first graph you would set these offsets to 0 (or something similar) so that the first graph appears in the normal place (where you are drawing them now). Then when you move onto the next graph you simply adjust the offsets so that the second graph is beside the first or below the first or whatever you like, then you do the same for the next two graphs when you draw them. This is probably the simplest approach.

If you have the graphs drawing OK, but they are positioned wrongly this should fix that problem. It's not unlike what you are doing with the coordinate system on screen except it takes a simpler approach. You could also get the coordinates of the printable page and make sure that you always scale your graphs to that size by applying an appropriate multiplier to each figure. Of course, you are then adding and multiplying each figure which might be better done in a function. For example:

  Function MapX(byval dXVal as Double) As Long
    ' Printer coordinates are always integers so we return a 
    ' long but accept a double just in case we need precision.
      Dim lResult as Long
      lResult = Int((dXVal + gXOffset) * gXScaleFactor)
      MapX = lResult
  End Function

Anyway I hope this has helped you out a little, at least given you an idea of how to approach your problem.


Image of Arrow to Previous Article

[TECH SUPPORT TOC]
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]