issues axAcroPDF. when closing form in c#

NazHim 206 Reputation points
2021-10-17T16:17:44.8+00:00

hi all.

issues axAcroPDF. when closing form in c#

i am used axAcroPDF for show pdf files on a form. in C# windows form application.
it's working perfectly good. but when closing the form. getting error. like image at below.

141152-untitled-01.png
141008-untitled-02.png
141153-untitled-03.png
141019-untitled-04.png
141146-untitled-05.png

how can solve this?
can give me?. some code snippet.?.

with best regards
NazHim

Developer technologies | Windows Forms
Developer technologies | C#
{count} votes

4 answers

Sort by: Most helpful
  1. P a u l 10,761 Reputation points
    2021-10-17T16:54:27+00:00

    Just as a test if you add this to your Form1 class does the issue persist?:

    protected override void OnClosed(EventArgs e) {
        axAcroPDF1.LoadFile("Empty");
    }
    
    0 comments No comments

  2. Castorix31 90,681 Reputation points
    2021-10-18T11:55:30.087+00:00

    I cannot reproduce your problem (Windows 10 1909, VS 2019, any .NET version)

    Maybe you can test with ATL as host (no need to add the reference for Adobe):

    At beginning :

    using System.Runtime.InteropServices;
    

    then :
    (remove the space at S leep, it is a bug in this editor...)

    public partial class Form1 : Form
    {
        [DllImport("Atl.dll", SetLastError = true)]
        public static extern bool AtlAxWinInit();
    
        [DllImport("Atl.dll", SetLastError = true)]
        public static extern int AtlAxGetControl(IntPtr h, [MarshalAs(UnmanagedType.IUnknown)] out object pp);
    
        public const int WS_OVERLAPPED = 0x0;
        public const int WS_BORDER = 0x00800000;
        public const int WS_POPUP = unchecked((int)0x80000000L);
        public const int WS_CHILD = 0x40000000;
        public const int WS_MINIMIZE = 0x20000000;
        public const int WS_VISIBLE = 0x10000000;
        public const int WS_DISABLED = 0x8000000;
    
        [DllImport("User32.dll", SetLastError = true)]
        public static extern IntPtr CreateWindowEx(int dwExStyle, string lpClassName, string lpWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
    
        public Form1()
        {
            //InitializeComponent();
            this.Load += new System.EventHandler(this.Form1_Load);
        }
    
        private IntPtr hWndContainer = IntPtr.Zero;
    
        private void Form1_Load(object sender, EventArgs e)
        {
            string sFile = @"E:\Sources\AcroPDF\Welcome.pdf";
            this.ClientSize = new System.Drawing.Size(800, 600);
            if (AtlAxWinInit())
            {
                hWndContainer = CreateWindowEx(0, "AtlAxWin", sFile, WS_VISIBLE | WS_CHILD | WS_BORDER, 10, 10, ClientSize.Width -20, ClientSize.Height -20, this.Handle, (IntPtr)10, IntPtr.Zero, IntPtr.Zero);
            }
            System.Threading.Thread.S leep(500);
            CenterToScreen();
        }
    }
    
    0 comments No comments

  3. harborsiem 1 Reputation point
    2021-10-20T07:20:05.613+00:00

    Do a similar solution in the Form closing event. pdf is your axAcroPDF1 in the following sample.

            private void PdfHelp_FormClosing(object sender, FormClosingEventArgs e) {
                if (e.CloseReason == CloseReason.UserClosing) {
                    this.dialog.Hide();
                    e.Cancel = true;
                } else if (e.CloseReason == CloseReason.FormOwnerClosing) {
    
                    if (pdf != null) {
                        pdf.Dispose();
                        this.dialog.Controls.Remove(pdf);
                        pdf = null;
                    }
                    this.dialog.Close();
                }
            }
    

    I have edited the sample (April 23, 2023). Now it should work without the Exception

    0 comments No comments

  4. NazHim 206 Reputation points
    2021-10-21T13:35:00.857+00:00

    hi harborsiem-2671

    thanks for your fast response
    but bad luck

    with best regards
    NazHim


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.