How do I print MSChart controls?

A

andrew

I have an application that requires graphical output.
I have added a MSChart to the application and want to be
able to print this out. I have a form which allows me to
print, and zoom in etc for images loaded into its picture
box space and so I thought it would be a matter of copying
the graph object to the clipboard and then casting its
Metafile format to a bitmap which I could then use to fill
the picturebox. Not so, although during debugging I can
see that there is data present, and it seems that my cast
of the enhanced metafile object to bitmap was successful
(i.e. there were no exceptions thrown) my Bitmap seems to
be set to Nothing.

Any ideas??

Relevant code is provided below:
Sub BeginCopyPaste()
Dim MyBmp As Bitmap
AxMSChart1.EditCopy() 'copies MSChart object to clipboard

'Create a new instance of the DataObject interface.
Dim data As IDataObject = Clipboard.GetDataObject()
' If the data is picture, then set the cast
'to bitmap and assign to picturebox
If (data.GetDataPresent
(DataFormats.EnhancedMetafile)) Then

MyBmp = CType(data.GetData
(DataFormats.EnhancedMetafile), System.Drawing.Bitmap)
PictureBox1.Image = MyBmp
End If
AxMSChart1.Hide()
'CODE RETURNS TO FORM WITH FOCUS. I EXPECTED TO SEE A
GRAPH IN A PICTURE BOX BUT SEE NOTHING
End Sub
 
O

One Handed Man [ OHM ]

One idea, but you're not going to like it !!

Obtain a colour photocopier and rest the monitor displaying the chart on top
face down. Press the start button on the copier and hey presto, colour
prints of your chart !

Sorry, I'm feeling very stupid and just could not resist that .


Regards - OHM
ROTFLMAO


I have an application that requires graphical output.
I have added a MSChart to the application and want to be
able to print this out. I have a form which allows me to
print, and zoom in etc for images loaded into its picture
box space and so I thought it would be a matter of copying
the graph object to the clipboard and then casting its
Metafile format to a bitmap which I could then use to fill
the picturebox. Not so, although during debugging I can
see that there is data present, and it seems that my cast
of the enhanced metafile object to bitmap was successful
(i.e. there were no exceptions thrown) my Bitmap seems to
be set to Nothing.

Any ideas??

Relevant code is provided below:
Sub BeginCopyPaste()
Dim MyBmp As Bitmap
AxMSChart1.EditCopy() 'copies MSChart object to clipboard

'Create a new instance of the DataObject interface.
Dim data As IDataObject = Clipboard.GetDataObject()
' If the data is picture, then set the cast
'to bitmap and assign to picturebox
If (data.GetDataPresent
(DataFormats.EnhancedMetafile)) Then

MyBmp = CType(data.GetData
(DataFormats.EnhancedMetafile), System.Drawing.Bitmap)
PictureBox1.Image = MyBmp
End If
AxMSChart1.Hide()
'CODE RETURNS TO FORM WITH FOCUS. I EXPECTED TO SEE A
GRAPH IN A PICTURE BOX BUT SEE NOTHING
End Sub

Best Regards - OHMBest Regards - OHM (e-mail address removed)
 
H

Herfried K. Wagner [MVP]

* "andrew said:
Relevant code is provided below:
Sub BeginCopyPaste()
Dim MyBmp As Bitmap
AxMSChart1.EditCopy() 'copies MSChart object to clipboard

'Create a new instance of the DataObject interface.
Dim data As IDataObject = Clipboard.GetDataObject()
' If the data is picture, then set the cast
'to bitmap and assign to picturebox
If (data.GetDataPresent
(DataFormats.EnhancedMetafile)) Then

MyBmp = CType(data.GetData
(DataFormats.EnhancedMetafile), System.Drawing.Bitmap)

What if you cast to 'System.Drawing.Image'?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top