.DrawPicture VB.Net

Posted by: SatishMatani on 11 April 2020, 1:41 pm EST

  • Posted 11 April 2020, 1:41 pm EST

    Hello,
    I am converting old VB6 program to VB.Net. The following worked fine in VB6

    .DrawPicture frmMain.vd.Picture, .CurrentX, .CurrentY, "15%", "33%"

    but following gives error in VB.Net
    .DrawPicture(frmMain.vd.Picture, .CurrentX, .CurrentY, "15%", "33%")
  • Replied 11 April 2020, 1:50 pm EST

    Error image attached
  • Replied 12 April 2020, 11:02 pm EST

    Hi Satish,

    I could replicate the issue at my end as well. Using VSPrinter's DrawPicture method does not allow skipping optional parameters, Align and Shade, in VB.Net. I have forwarded it to the developers [Internal Tracking ID: 430976] and will let you know once there is any information from them.

    Thanks,
    Pragati
  • Replied 13 April 2020, 6:30 pm EST

    Satish,

    I discussed the case with the developers. The Interop interfaces are not generated by GrapeCity, but rather by VB.NET. As such GrapeCity has very little control of the overloads generated by the VB.NET software. When dropping the control on a form, 2 overloads are generated by VB.NET - one with 3 arguments and one with 7 arguments. One or the other must be used.

    ActiveX controls (Windows native) are not directly accessible by .NET software. To use them, Visual Studio .NET generates intermediate code to allow operations between the two (.NET and native code) - an Interop. It is the generated interop software that limits the overloads without default values. And, hence the difference from VB6.

    Thanks.
  • Replied 14 April 2020, 4:33 am EST

    Pragati,

    Thank you for a quick response. Pardon me for my ignorance. But not sure what you are getting at. What is the solution? How can I make this work? How do I use .DrawPicture(frmMain.vd.Picture, .CurrentX, .CurrentY, "15%", "33%"). Please help.
  • Replied 14 April 2020, 10:27 pm EST

    Hi Satish,

    The solution is to either use the overload with 3 arguments (Picture As Picture, Left As Variant, Top As Variant) or the one with 7 arguments (Picture As Picture, Left As Variant, Top As Variant, [ Width As Variant ], [ Height As Variant ], [ Align As Variant ], [ Shade As Variant ]) in VB.Net.

    Thanks,
    Pragati
  • Replied 15 April 2020, 11:58 am EST

    Pragati,

    What value do I assign for Align and Shade variant? The documentation does not say anything about it
  • Replied 15 April 2020, 10:41 pm EST

    Hi Satish,

    Here is the correct link from the documentation:
    https://help.grapecity.com/componentone/NetHelp/vsview8/drawpicturemethodvsprinter.html

    It is VSPrinter's DrawPicture method.

    Thanks,
    Pragati
  • Replied 17 April 2020, 8:31 am EST

    Pragati,

    Thanks. One step closer. Above with EnhancedMatafile does not work.

    VB6 code:
    frmChart.ChartV.CopyToClipboard oc2dFormatEnhMetafile
    .DrawPicture Clipboard.GetData(3), .CurrentX, .CurrentY "60%", "60%"

    VB.Net code frmChart.ChartV.CopyToClipboard(C1Chart2D8.FormatConstants.oc2dFormatEnhMetafile) .DrawPicture(Clipboard.GetDataObject().GetData(DataFormats.EnhancedMetafile), .CurrentX, .CurrentY, "60%", "60%", 10, False)

    but it works with Bitmap
    frmChart.ChartV.CopyToClipboard(C1Chart2D8.FormatConstants.oc2dFormatBitmap)
    .DrawPicture(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), .CurrentX, .CurrentY, "60%", "60%", 10, False)

    What am I doing wrong?
    Thx
  • Marked as Answer

    Replied 21 April 2020, 9:07 pm EST

    Satish,

    Can you please give me a small sample replicating this? That would help me in assisting you further at the earliest.

    ~Pragati
  • Replied 30 April 2020, 2:03 pm EST

    Attached is the sample. Click on Button 1.

    Also, I have another issue. Following line worked in vb6
    .DrawPicture frmMain.vd.Picture, .CurrentX, .CurrentY, "20%", "33%"
    but following in VB.Net does not work.
    DrawPicture(Form1.vd.Picture, .MarginLeft, .CurrentY, "50%", "50%", "10", False)
    It gives error. It is line 31 in Form2_load which I have REM out.
    ThxVSPrint Ex - Copy.zip
  • Replied 30 April 2020, 10:10 pm EST

    Hi Satish,

    I am discussing both the issues with the developer [tracking ID: 433517]. Will get back to you once there is any information from them.

    Thanks,
    Pragati
  • Replied 30 May 2020, 2:42 am EST

    Any update?
  • Replied 2 June 2020, 9:01 pm EST

    Hi Satish,

    I have asked the developer for an update on this. Will notify you once there is any information from him.

    Thanks.
  • Replied 14 June 2020, 2:53 am EST

    Just wondering if you heard back from the developer on this?
  • Replied 14 June 2020, 9:09 pm EST

    Not yet, Satish. I will update the thread once there is something.

    I would also like you to know that ActiveX Edition is in maintenance mode and there is no active development going for the product. We only fix critical issues though.

    Thanks,
    Pragati
  • Replied 19 July 2020, 2:31 am EST

    Hi Pragati,

    I understand ActiveX Edition is in maintenance mode and you only fix critical issues. I consider being able to print vd picture a critical issue. It is clearly a feature of VSprint and documented in the control and design example VSDraw.

    This item is very critical for me to convert my old VB program to VB.net and the last remaining issue. I beg you to look into it and let me know or provide a work around.

    Thank you for your understanding and stay safe.
  • Replied 22 July 2020, 11:02 pm EST

    Hello,

    I understand the criticality of the issue for you, hence have forwarded your comments to the concerned developer and have requested for a workaround while the issue is under investigation.
    I will get back to you as soon as there is an update.

    Regards,
    Ruchir
  • Replied 2 October 2020, 11:52 am EST

    Just wondering if there is any resolution on this issue?
  • Replied 5 October 2020, 10:13 pm EST

    Hi Satish,

    Let me connect to the developer once and get back to you on this as soon as possible.

    Thanks.
  • Replied 25 October 2020, 11:13 pm EST

    Hi Satish,

    .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:

    https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.clipboard?view=netcore-3.1

    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:

    Microsoft.VisualBasic.Compatibility.VB6.ImageToIPicture(image)

    method used to convert the .NET Image to an IPicture.

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    With AxVSPrinter1

    'Setup page and fonts
    .MarginTop = "2.25in"
    .MarginBottom = "0.5in"
    .MarginLeft = "0.75in"
    .MarginRight = "0.75in"
    .FontSize = 10
    .LineSpacing = 115
    .Columns = 2
    .StartDoc()
    .Paragraph = ""

    .Paragraph = "Bitmap Chart"
    Form1.AxChart2D1.CopyToClipboard(C1Chart2D8.FormatConstants.oc2dFormatBitmap)
    .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()
    Form1.AxChart2D1.DrawToFile(fn, C1Chart2D8.FormatConstants.oc2dFormatEnhMetafile)

    '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()
    img.Dispose()
    File.Delete(fn)

    '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).
    .GetOcx().DrawPicture(Microsoft.VisualBasic.Compatibility.VB6.ImageToIPicture(img2), _
    .MarginLeft, .CurrentY, "50%", "50%", "10", False)
    img2.Dispose()

    .CurrentY = "6in"
    .EndDoc()

    End With
    End Sub

    Thanks,
    Pragati
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels