c# - 无法在子窗口中查看 pdf 文件

标签 c# winforms pdf-viewer

我在 Parent 窗口中有以下代码。

private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
    Help helpWindow=new Help();
    helpWindow.MdiParent = this;
    helpWindow.BringToFront();
    helpWindow.Show();        
}

窗口代码如下。

public Help()
{
    InitializeComponent();
    axAcroPDF1.LoadFile(@"D:\sample.pdf");
}

如果我使用上面的代码,我无法在我的子窗口中查看 pdf。但是如果我删除下面的代码 helpWindow.MdiParent = this; 从父窗口,我可以查看 pdf,但它在一个单独的窗口中打开,这不是我的要求。

最佳答案

是否有可能您的帮助窗口只是被父 Form 上的其他控件隐藏了?也许是 PanelDockStyleFill?我不相信 BringToFront() 会覆盖父级 Form 的前台控件。

从给定的信息来看,您的 PDF 查看表单的代码似乎没问题,这取决于您所说的“我无法在我的子窗口中查看 pdf。”/p>

无论如何,你可以做这样的事情来查看你的子窗口是否被隐藏:

private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
     foreach (Control ctrl in this.Controls)
     {
          if (!(ctrl is MdiClient))
              ctrl.Hide();                                 
     }

     Help helpWindow=new Help();
     helpWindow.MdiParent = this;
     helpWindow.FormClosing += helpWindow_FormClosing;
     helpWindow.BringToFront();
     helpWindow.Show(); 
}

private void helpWindow_FormClosing(object sender, FormClosingEventArgs e)
{
    foreach (Control ctrl in this.Controls)
    {
        ctrl.Show();
    }
}

关于c# - 无法在子窗口中查看 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22345962/

相关文章:

ASP.NET PDF 查看器

Android:如何在特定页面打开PDF文件

c# - 无法在带有输入字段 Unity 的 Scroll rect 中滚动

c# - 打印发票 C# Winforms

c# - 使 ASP.NET Identity 2.0 电子邮件确认 token 适用于 WCF 和 MVC

c# - 使用 Linq 2 Sql 拍摄项目的快照(克隆)

c# - .NET Winforms 控件是否使用 MSCOMCTL.OCX?

c# - 将保存按钮绑定(bind)到 DataTable

c# - 以编程方式将 DNS 设置为 'Obtain automatically'

ios - 使用我的APP打开PDF文件