簡體   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