Displaying Excel chart image in Picturebox using VB.net

  • Thread starter Thread starter Stan
  • Start date Start date
S

Stan

In the old days of VB6, an Excel chart image could be
pasted into a picture box with Clipboard using the
following commands.

xlApp.ActiveChart.ChartArea.Copy
Picture1.Picture = Clipboard.GetData()


I having problems doing this in VB.net? I tried the code
shown below, but it does not work. Its a modified version
of a Clipboard-bitmap example I found on the Microsoft
support site. I believe Excel Chart images copied onto
Clipboard as a enchanced metafile.

xlApp.ActiveChart.ChartArea.Copy

Dim oDataObj As IDataObject =
System.Windows.Forms.Clipboard.GetDataObject()

If Not System.Windows.Forms.Clipboard.GetDataObject() Is
Nothing Then

If oDataObj.GetDataPresent
(System.Windows.Forms.DataFormats.MetafilePict) Then
PictureBox1.Image = oDataObj.GetData
(DataFormats.EnhancedMetafile, True)
End If

End If


Please help!
 
Back
Top