A PrintScreen Utility

Team Fly 

Page 186

After printing a row, the program draws the horizontal line that separates it from the following row. The vertical lines are printed last, because we need to know the vertical coordinate of the last row on the page. The code isn't really complicated, but it's quite lengthy. We've inserted comments to explain its operation and we hope you'll find these comments useful in customizing the printing process.

A PrintScreen Utility

The last sample in this chapter is rather odd, in the sense that it uses API calls to capture the screen (or the current window) and print it. I've received requests from readers in the past about a simple technique to print a form. Obviously, many VB6 programmers used this technique in the past and they need a quick mechanism to generate printouts of the current window. Our recommendation is that you write code to generate proper printouts, as explained in the preceding sections of this chapter. If you think a screen-printing utility suits you, use the code of the PrintScreen sample application. Figure 7.9 shows the preview of a screen capture.

While printing the current form in VB6 was trivial, there's no simple mechanism in GDI+ to capture the screen. The closest we were able to come to a screen-printing utility was to use the BitBlt GDI32 function. This function can copy the bitmap from any device context onto any compatible device context. We'll use it to copy the entire screen (or the current window) onto an Image object, and then we will use the .NET Framework's printing mechanism to send the bitmap to the printer. The current window is not the active window on the desktop. By ''current window" we mean the form that contains the code. There's no simple mechanism to capture a keystroke meant for another application, and our code can't print any other window (the "active" window) on the desktop.

Start a new project, the PrintScreen project, and paste the function declarations from Listing 7.5 at the form's level. These are three API functions that we'll call from within our VB.NET application.

image

FIGURE 7.9 Printing the screen, or the current window

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net