dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Show a PDF file in a MDI application of C#

  1. #1
    Join Date
    Nov 2007
    Posts
    4

    Question Show a PDF file in a MDI application of C#

    Hello everybody, I encounter a problem and need your help.

    In a MDI application of C#, I want to show a PDF file in a child form. I have added a PDF browser to the child form and change it to pulic, just like below:
    public AxAcroPDFLib.AxAcroPDF pdfBrowser;

    When the MDI load, my code likes below:
    Code:
    private void MDIFrm_Load(object sender, EventArgs e)
            {
                ChildFrm myChildFrm = new ChildFrm();
                myChildFrm.pdfBrowser.LoadFile("C:\\dev\\linux-i18n-intro.pdf");
                myChildFrm.MdiParent = this;
                myChildFrm.Show();
            }
    However,I can not see the PDF content in the Child form,but if I set the ChildFrm as the strartup object,it will show PDF correctly.

    Could anyone give some suggestions?
    Thanks very much!
    Last edited by lizhizhe2000; December 6th, 2007 at 04:56 AM.

  2. #2
    Join Date
    Nov 1999
    Location
    Denmark
    Posts
    260

    Re: Show a PDF file in a MDI application of C#

    ChildFrm myChildFrm = new ChildFrm();
    should prob not be inside your function
    as object instantiated are garbage collected when the function looses scope

  3. #3
    Join Date
    Nov 2007
    Posts
    4

    Re: Show a PDF file in a MDI application of C#

    Quote Originally Posted by Rudegar
    ChildFrm myChildFrm = new ChildFrm();
    should prob not be inside your function
    as object instantiated are garbage collected when the function looses scope
    Well,I have modifed my code according to your suggestion,however,it still can not show the PDF file correctly.

  4. #4
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487

    Re: Show a PDF file in a MDI application of C#

    have you tried to load the PDF when the form shown?

    Code:
    private void MDIFrm_Load(object sender, EventArgs e)
            {
                ChildFrm myChildFrm = new ChildFrm();
                myChildFrm.MdiParent = this;
                myChildFrm.Show();
    
                
                myChildFrm.pdfBrowser.LoadFile("C:\\dev\\linux-i18n-intro.pdf");
                
    
            }
    Busy

  5. #5
    Join Date
    Nov 2007
    Posts
    4

    Re: Show a PDF file in a MDI application of C#

    to:have you tried to load the PDF when the form shown?
    ---------------------------------------------------------------
    Yes,I do load the PDF file before show the child form,my code likes below:
    Code:
            private void MDIFrm_Load(object sender, EventArgs e)
            {
                myChildFrm = new ChildFrm();
                myChildFrm.pdfBrowser.LoadFile("C:\\dev\\linux-i18n-intro.pdf");                    
                myChildFrm.MdiParent = this;
                myChildFrm.Show();        
            }
    If anyone is interesting,you can reproduce this problem on your computer!It is easy to duplicate:
    1.Click right mouse button on you toolbos->Choose Items->Change to the "COM components"->Add "Adobe Acrobat 7.0 Browser Document" to your toolbox
    2. Create two form,one is MDI container,and other is child form.Drag the "Adobe Acrobat 7.0 Browser Document " to your child form.

  6. #6
    Join Date
    Jan 2010
    Posts
    3

    Re: Show a PDF file in a MDI application of C#

    lizhizhe2000 - were you ever able to solve this problem? I'm dealing with the same situation and I'm desperate for a solution!!

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,227

    Re: Show a PDF file in a MDI application of C#

    Looks like Show() causes the form to go out of scope and close. Try .ShowDialog( ).

  8. #8
    Join Date
    Jan 2010
    Posts
    3

    Re: Show a PDF file in a MDI application of C#

    Arjay, maybe I'm missing something but ShowDialog doesn't make a whole lot of sense to me when used on an MDI child.

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,227

    Re: Show a PDF file in a MDI application of C#

    Quote Originally Posted by mattyt View Post
    Arjay, maybe I'm missing something but ShowDialog doesn't make a whole lot of sense to me when used on an MDI child.
    If you use ShowDialog, you can check if the form appears and know whether it's a pdf loading issue or a form going out of scope issue. If the pdf appears with ShowDialog, you know it's variable going out of scope issue.

  10. #10
    Join Date
    Jan 2010
    Posts
    3

    Thumbs up Re: Show a PDF file in a MDI application of C#

    OK, thanks for the clarification!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)