Click here to Skip to main content
15,892,839 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am using PrintPreviewDialog to preview text boxes in PDF but when I preview it for the first time and close the preview dialogue and if I try to preview again it gives me a message “cannot access a disposed oblect. Object name: PrintPreviewDialog”

What I have tried:

I have tried to add a code line that sets isDisposed == false, it does work
Posted
Updated 24-Feb-20 7:45am
Comments
[no name] 4-Dec-19 12:43pm    
can you share your Dispose method if you are using IDisposable pattern?
are you disposing object during close?

one reason could be that object is disposed when you closed first time.
in c# best way to dispose any object is IDisposable pattern. if you do not want to dispose the object which you want to keep it memory for some time then make sure you change the dispose behavior of that object in such case you dispose when their parent is disposed.
Class A : Idiposable
{
   public B obj;

// call whenever it is required.
   void Dispose()
{
  obj.Dispose();
  
}
} 

Class B : Idiposable
{
   void Dispose()
{
 Dispose any third party obj etc. like printview etc.
}
}


you can add more detail if it is not clear. but i have told you the solution in general for any Dispose type of object, this will help you understand Dispose pattern as well.
 
Share this answer
 
You're trying to use an instance of the PrintPreviewDialog after you've called Dispose on it.

Either change your code so that you don't call Dispose until you've finished with the instance; or change your code to create a new instance when needed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900