Microsoft KB Archive/168749

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 11:03, 21 July 2020 by X010 (talk | contribs) (Text replacement - """ to """)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


How To Print the Contents of the MS Chart Control

Article ID: 168749

Article Last Modified on 7/1/2004



APPLIES TO

  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition



This article was previously published under Q168749

SUMMARY

The MSChart control does not expose a method that enables you to print the chart directly. However, you can use the PrintForm method to print the entire form containing the MSChart control. This article describes a method for printing only the chart.

MORE INFORMATION

You can print the chart of an MSChart control by copying the contents of the control using the EditCopy method, retrieveing the chart from the Clipboard, and then printing the picture via the PaintPicture method of the Printer object:

  1. Start a new Standard EXE project. Form1 is created by default.
  2. Click Components on the Project menu. Check "Microsoft Chart Control" and click OK.
  3. Draw an MSChart control and a CommandButton on Form1.
  4. Add the following code to the Click event of Command1 on Form1:

          MSChart1.EditCopy
          DoEvents   ' may be needed for large datasets
          Printer.Print " "
          Picture1.PaintPicture Clipboard.GetData(), 0, 0
          Printer.EndDoc
    
                            
  5. Run the application. Click the CommandButton to print the chart to your default printer.

    NOTE: The EditCopy method copies both the data and the picture of the chart to the clipboard. Then, when you use a Paste command to retrieve the contents of the clipboard, the receiving application determines whether the picture or the data is pasted. In this example, PaintPicture requests the clipboard data and receives a picture of the chart rather than the chart's data. You could also specify this with Clipboard.GetData(vbCFBitmap).



Additional query words: kbVBp500 KBComp KBCtrl Kbprinting kbprint kbVBp

Keywords: kbhowto kbprint kbctrl KB168749