Replied 25 October 2020, 11:13 pm EST
.NET and native/ActiveX handling of metafile pictures and images are different difficult to make work using only the Interop generated by VisualStudio. These issues are mentioned in Microsoft documentation - for example:
In the above link to the Clipboard class documentation, at the bottom of the notes section of the remarks:
"Special considerations may be necessary when using the metafile format with the Clipboard. Due to a limitation in the current implementation of the DataObject class, the metafile format used by the .NET Framework may not be recognized by applications that use an older metafile format. In this case, you must interoperate with the Win32 Clipboard application programming interfaces (APIs)."
Both the C1Chart and VSPrinter ActiveX controls use the native Win32 formats for EnhancedMetafiles as they must be compatible with VB6 for which they were originally written. When using VB.NET, rather than using the ActiveX controls, users should consider using the .NET controls written specifically for the .NET environment.
If ActiveX controls must be used, then alternative compatibility methods must be used.
Below is a modified version of the Form2_Load event in the customer example. The modifications use the .GetOcx() method of the ActiveX interop module to pass an IPicture object (ActiveX object for handling of an Image) directly to the Ocx VSPrinter control rather than using the generated interop.
Additionally, the Microsoft.VisualBasic.Compatibility.dll is added as a reference and the:
method used to convert the .NET Image to an IPicture.
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Setup page and fonts
.MarginTop = "2.25in"
.MarginBottom = "0.5in"
.MarginLeft = "0.75in"
.MarginRight = "0.75in"
.FontSize = 10
.LineSpacing = 115
.Columns = 2
.Paragraph = ""
.Paragraph = "Bitmap Chart"
.DrawPicture(Clipboard.GetData("Bitmap"), .MarginLeft, .CurrentY, "50%", "50%", "10", False)
.CurrentY = "4in"
.Paragraph = "Enhanced Meta File"
'Create a temp file with the enhanced meta file and have the chart draw to the file.
Dim fn As String = System.IO.Path.GetTempFileName()
'Create an image from the metafile file. To avoid having temp files laying around,
'the temp file needs to be deleted, but cannot be deleted if the metafile is given
'to the OCX. To avoid issues, clone the metafile image so a memory copy is made and
'pass that to the OCX. Dispose and delete the temp file.
Dim img As Image = Image.FromFile(fn)
Dim img2 As Image = img.Clone()
'Because the Interop does not handle IPicture conversions well, use the VB6 compatibility
'and the raw OCX to make a direct call to the OCX (i.e. AxVSPrinter1.GetOcx() returns the raw OCX).
.MarginLeft, .CurrentY, "50%", "50%", "10", False)
.CurrentY = "6in"