locked
AxAcroPDF doesent work when using MDI RRS feed

  • 问题

  • Hello

    i'm working on a MDI application and need to view a ".PDF" files in a MDI child form, but when using the AxAcroPDF control it doesent work, note that it works fine when viewing the form separately from the MDI application.

    anyone can help ?

    thanks

    2010年11月26日 13:52

答案

  • Hi Saadi.A

    I tesed your code and find the cause is that we should invoke AxAcroPDF1.CreateControl()  this AxtiveX BeginInit(). So we could add the code in the Form2.Designer.vb:

      Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form2))
        Me.AxAcroPDF1 = New AxAcroPDFLib.AxAcroPDF()
        CType(Me.AxAcroPDF1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'AxAcroPDF1
        '
        AxAcroPDF1.CreateControl()
        Me.AxAcroPDF1.Dock = System.Windows.Forms.DockStyle.Fill
        ......
    
    Sincerely,
    Bob Bao
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download All in One Code Framework !

    如果有回复帮助并解决了您的问题,请点击 “标记为答复”,如果没有没有帮助,请随时点击“取消答复标记”
    你在为寻找代码示例而苦恼吗?赶快来下载 All in One Code Framework 微软一站式代码框架 吧!
    • 已标记为答案 Saadi.A 2010年12月1日 10:15
    2010年12月1日 8:47

全部回复

  • Are you getting any error message like below  "System.Windows.Forms.AxHost+InvalidActiveXStateException' was thrown

    if yes, then the error indicates that you try to use activex control before it fully initialized. You need to allow the child form to shown before doing anything with activex

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    2010年11月26日 15:15
  • Thanks Kaymaf but i didn't get any error, i just get a blank document when the child form loads.
    2010年11月27日 20:33
  • Thanks Kaymaf but i didn't get any error, i just get a blank document when the child form loads.


    show the code where you load the child form

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    2010年11月27日 21:05
  • Here is the Code that will load the child form

    If helpForm Is Nothing OrElse helpForm.IsDisposed Then
       childForm += 1
       helpForm = New HelpForm()
       helpForm.MdiParent = Me
       Me.SplitContainer1.Panel2.Controls.Add(helpForm)
       helpForm.Show()
       helpForm.BringToFront()
      Else
    

    and Here is the code inside the Child form Load event

    AxAcroPDF1.LoadFile("File1.pdf")
    AxAcroPDF1.Show()
    

    Thanks Kaymaf for your interesting 

    2010年11月28日 9:03
  • Your code should work but not sure why is not.  Below is code that i tested with MDI form, it create new form and PDF control at runtime and it works

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim fr As New Form
            fr.Text = "MDI"
            fr.MdiParent = Me
            fr.ShowIcon = False
            fr.Show()
            Dim AxAcroPDF1 As New AxAcroPDFLib.AxAcroPDF
            fr.Controls.Add(AxAcroPDF1)
            AxAcroPDF1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                        Or System.Windows.Forms.AnchorStyles.Left) _
                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)

            AxAcroPDF1.Enabled = True
            AxAcroPDF1.Location = New System.Drawing.Point(2, 5)
            AxAcroPDF1.Name = "AxAcroPDF1"
            AxAcroPDF1.OcxState = CType(AxAcroPDF1.OcxState, System.Windows.Forms.AxHost.State)
            AxAcroPDF1.Size = New System.Drawing.Size(288, 257)
            AxAcroPDF1.TabIndex = 0
            AxAcroPDF1.src = Application.StartupPath & "\fla.pdf"
            AxAcroPDF1.setShowToolbar(False)
     End Sub

    Also, try to change loadFile to SRC

    kaymaf


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    2010年11月28日 14:09
  • Thanks Kaymaf, but i had tried to change the LoadFile to Src and change a lot of things but nothing works.

    thanks a lot

    Saadi 

    2010年11月28日 20:33
  • Hi Saadi.A

    Try to use AxAcroPDF1.LoadFile(filename) method to show the PDF file. the following is a sample that show a PDF viewer in WPF, may help you: http://hugeonion.com/2009/04/06/displaying-a-pdf-file-within-a-wpf-application/

    Sincerely,
    Bob Bao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download All in One Code Framework !

    如果有回复帮助并解决了您的问题,请点击 “标记为答复”,如果没有没有帮助,请随时点击“取消答复标记”
    你在为寻找代码示例而苦恼吗?赶快来下载 All in One Code Framework 微软一站式代码框架 吧!
    2010年11月30日 10:11
  • Thanks Bob Bao, But i had tried to use the AxAcroPDF1.LoadFile(filename) method and as i said in the previous replies about this subject it works fine when viewing it in a form that is not considered as a child form of a MDI parent, the problem is that when using the AxAcroPDF in a child form of a MDI parent it shows nothing, just a blank document.

    thanks again Bob Bao

    Saadi

    2010年11月30日 11:33
  • Hi Saadi.A,

    Could you please share a ready-to-run sample here, or you could update it to the Skydrive.com, that we can repro your issue, and help you to change it?

    Thanks!

    Sincerely,
    Bob Bao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download All in One Code Framework !

    如果有回复帮助并解决了您的问题,请点击 “标记为答复”,如果没有没有帮助,请随时点击“取消答复标记”
    你在为寻找代码示例而苦恼吗?赶快来下载 All in One Code Framework 微软一站式代码框架 吧!
    2010年11月30日 11:43
  • Hi Bob Bao,

    i added a Sample Project of the problem on my SkyDrive in the public folder

    Thanks Bob Bao

    2010年11月30日 13:11
  • Hi Bob Bao

    Sorry about that, here is the SkyDrive Link http://cid-fd4477b84630c94c.office.live.com/browse.aspx/.Public

    thanks Bob Bao

    Saadi

    2010年11月30日 16:55
  • Hi Saadi.A

    I tesed your code and find the cause is that we should invoke AxAcroPDF1.CreateControl()  this AxtiveX BeginInit(). So we could add the code in the Form2.Designer.vb:

      Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form2))
        Me.AxAcroPDF1 = New AxAcroPDFLib.AxAcroPDF()
        CType(Me.AxAcroPDF1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'AxAcroPDF1
        '
        AxAcroPDF1.CreateControl()
        Me.AxAcroPDF1.Dock = System.Windows.Forms.DockStyle.Fill
        ......
    
    Sincerely,
    Bob Bao
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Are you looking for a typical code sample? Please download All in One Code Framework !

    如果有回复帮助并解决了您的问题,请点击 “标记为答复”,如果没有没有帮助,请随时点击“取消答复标记”
    你在为寻找代码示例而苦恼吗?赶快来下载 All in One Code Framework 微软一站式代码框架 吧!
    • 已标记为答案 Saadi.A 2010年12月1日 10:15
    2010年12月1日 8:47
  • Thanks a lot Bob Bao, it works fine now

    Saadi

    2010年12月1日 10:16
  • Hi Kaymaf,

    Thankyou very very much for this post, I was ready to buy a Activex for viewing pdf in a mdichild form.

    It works perfect now , keep up the good work!!!

    Steven

     

    2011年3月11日 13:46