Microsoft KB Archive/197487

= BUG: MSChart EditCopy Sends Incorrect Legends To Clipboard =

Article ID: 197487

Article Last Modified on 5/13/2003

-

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 Q197487



SYMPTOMS
The EditCopy method of the MSChart control is used to send a copy of the chart to the clipboard. When the clipboard contents are pasted or saved, any chart legends display only their default values ("C1", "C2", and so forth) instead of the values that were specified by the program.



RESOLUTION
Create an image of the chart using a PictureBox control and send the image to the clipboard.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a Visual Basic Standard EXE project. Form1 is created by default. From the Project menu, choose Components, which opens the Components dialog box. Click "Microsoft Chart Control", and then click OK. Add a Chart control to Form1 and set the chart's ShowLegend property to True.  Add the following code to the General Declarations section of Form1: Option Explicit

Private Sub Form_Load ' Set the chart legends to some text value MSChart1.Plot.SeriesCollection.Item(1).LegendText = "Total Space" MSChart1.Plot.SeriesCollection.Item(2).LegendText = "Used Space" ' Call the EditCopy method to send the chart to the clipboard MSChart1.EditCopy ' Save the data on the clipboard as a bitmap ' you can also use clipboard viewer to see everything SavePicture Clipboard.GetData, "c:\test1.bmp" End Sub  Run the program and the bitmap image of the chart control is stored in the file C:\test1.bmp. Open the file test1.bmp using Paint, the Clipboard Viewer, or another image editor. The default values of the legend text were used rather than the values set by the sample program.</li></ol>

Steps to Workaround the Problem
<ol> Create a Visual Basic Standard EXE project. Form1 is created by default.</li> From the Project menu, choose Components, which opens the Components dialog box. Click "Microsoft Chart Control", and then click OK.</li> Add a Chart, a CommandButton, and a PictureBox control to Form1.</li> Set the ShowLegend property of MSChart1 to True.</li>  Add the following code to the General Declarations section of Form1: Option Explicit

Private Declare Function SendMessage Lib "user32" Alias _ "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _       ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_PAINT = &HF Private Const WM_PRINT = &H317 Private Const PRF_CLIENT = &H4&   ' Draw the window's client area. Private Const PRF_CHILDREN = &H10& ' Draw all visible child windows. Private Const PRF_OWNED = &H20&   ' Draw all owned windows.

Private Sub Command1_Click Dim rv As Long ' Make sure picturebox is same size as the chart. With Picture1 .Height = MSChart1.Height .Width = MSChart1.Width End With

Picture1.AutoRedraw = True rv = SendMessage(MSChart1.hwnd, WM_PAINT, Picture1.hDC, 0) Picture1.Picture = Picture1.Image Picture1.AutoRedraw = False

' Sent the picture to the clipboard. Clipboard.Clear Clipboard.SetData Picture1.Picture

' Save the picture on disk. SavePicture Form1.Picture1.Picture, "c:\testpic.bmp" End Sub

Private Sub Form_Load ' Set our legends. With MSChart1 .Plot.SeriesCollection.Item(1).LegendText = "Total Disk Space" .Plot.SeriesCollection.Item(2).LegendText = "Used Disk Space" End With Picture1.Visible = False End Sub </li> Run the program and click Command1 to store the bitmap image of the chart control in the file C:\testpic.bmp.</li> Open the file testpic.bmp using Paint or another image editor. You can also use the clipboard viewer to directly view the clipboard contents. Since the bitmap was created using the image on the screen, the legend text appears correctly as part of the image.</li></ol>

<div class="references_section">