简体   繁体   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();
    }

This is my code. 这是我的代码。 I made my code so after i get what i want to print, it opens a print preview dialong and in it swapped the print button for a prind dialong button, which in the end prints it. 我编写了代码,因此在获得要打印的内容后,它会打开一个打印预览Dialong,并在其中将打印按钮替换为prind Dialong按钮,最后将其打印出来。 I found how to do that in a question in stackoverflow. 我在stackoverflow中的一个问题中找到了如何做的。

Anyway this works perfectly fine in Visual Studio with debugging. 无论如何,这在Visual Studio中通过调试可以很好地工作。 But when i publish the project it gives me this error. 但是当我发布项目时,它给了我这个错误。

If anyone knows what to do about this i would greatly appreciate it since I can't find exactly why this is like that, in the meanwhile i'm looking for a workaround. 如果有人知道该怎么做,我将不胜感激,因为我找不到确切的原因,与此同时,我正在寻找解决方法。

Thanks in advance! 提前致谢!

Regards Thomas! 问候托马斯!

So if anyone runs into the same problem and finds this the fix was actually pretty easy, but took me a bit of time to pinpoint. 因此,如果有人遇到相同的问题并发现此问题,修复实际上很容易,但是我花了一些时间来确定。 My problem was the fact that i was generating bitmap images from files i had in my project folder, but did not add them to rescources. 我的问题是我从项目文件夹中的文件生成位图图像,但没有将它们添加到资源库中。 So when i published my program those did not transfer with it. 因此,当我发布程序时,这些程序并没有随之转移。 The simple fix is to just add them ass rescources and generate them from there Replace : 简单的解决方法是只添加它们的资源库,并从那里生成它们Replace:

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

With: 附:

logo = Properties.Resources.Pgd_glava;

Really is a rookie mistake on my behalf, but i just never published the programs i made up till this point. 确实代表我是一个菜鸟错误,但是到目前为止,我从未发布过我编写的程序。

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

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