简体   繁体   中英

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. I found how to do that in a question in stackoverflow.

Anyway this works perfectly fine in Visual Studio with debugging. 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 :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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