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");
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
how can solve this?
can give me?. some code snippet.?.
with best regards
NazHim
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");
}
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();
}
}
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
hi harborsiem-2671
thanks for your fast response
but bad luck
with best regards
NazHim