繁体   English   中英

printdocument和对话框中的C#错误在VS中有效,但发布项目后无效

[英]C# error in printdocument and dialog works in VS but not after publishing my project

private void bPrint_Click(object sender, EventArgs e)
    {
        curitems = 1;
        page = 1;
        count = 1;
        printDocument1.DocumentName = tBPor.Text;
        logo = new Bitmap("Pgd_glava.jpg",true);
        printDialog1.Document = printDocument1;
        printDialog1.AllowSelection = true;
        printDialog1.AllowSomePages = true;
        printPreviewDialog1.Document = printDocument1;
        ToolStripButton b = new ToolStripButton();
        b.Image = new Bitmap("print.png");
        b.DisplayStyle = ToolStripItemDisplayStyle.Image;
        b.Click += printPreview_PrintClick;
        ((ToolStrip)(printPreviewDialog1.Controls[1])).Items.RemoveAt(0);
        ((ToolStrip)(printPreviewDialog1.Controls[1])).Items.Insert(0, b);
        printPreviewDialog1.Document = printDocument1;
        printPreviewDialog1.ShowDialog();
    }

这是我的代码。 我编写了代码,因此在获得要打印的内容后,它会打开一个打印预览Dialong,并在其中将打印按钮替换为prind Dialong按钮,最后将其打印出来。 我在stackoverflow中的一个问题中找到了如何做的。

无论如何,这在Visual Studio中通过调试可以很好地工作。 但是当我发布项目时,它给了我这个错误。

如果有人知道该怎么做,我将不胜感激,因为我找不到确切的原因,与此同时,我正在寻找解决方法。

提前致谢!

问候托马斯!

因此,如果有人遇到相同的问题并发现此问题,修复实际上很容易,但是我花了一些时间来确定。 我的问题是我从项目文件夹中的文件生成位图图像,但没有将它们添加到资源库中。 因此,当我发布程序时,这些程序并没有随之转移。 简单的解决方法是只添加它们的资源库,并从那里生成它们Replace:

logo = new Bitmap("Pgd_glava.jpg",true);

附:

logo = Properties.Resources.Pgd_glava;

确实代表我是一个菜鸟错误,但是到目前为止,我从未发布过我编写的程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM