2017-04-27 54 views
1

請幫助我是C#的新手,我有一個帶有textbox1,textbox2和buttom1的窗體,我希望在不預覽的情況下打印textbox1的值或讓它我直接對打印機說沒有任何交互,文本框的值必須是我想要打印的capies的數量,也是頁碼所有這些副本說如果我輸入3應該說第1/3頁2/3 3/3請大家幫忙,請原諒,我的英語 我有我的按鈕根據文本框輸入打印份數並放置頁碼C#

private void button1_Click(object sender, EventArgs e) 
    { 


     PrintDocument printDocument = new PrintDocument(); 
     printDocument.DefaultPageSettings.Landscape = true; 
     printDocument.DefaultPageSettings.PaperSize = new PaperSize("zed", 400, 850); 
     //printDocument.PrinterSettings.Copies = 2; 
     printDocument.PrintPage += PrintDocumentOnPrintPage; 
     printDocument.Print(); 
+0

查看'int.TryParse' - 如果將文本值轉換爲int成功,則返回true,否則返回false。你可以採取一個文本框的值,並將其轉換爲一個整數傳遞給.Copies :) – john

+0

好的謝謝很多約翰確實通過一個研究轉換它和整數,因爲我說我是這個東西的新手 int i = 0; i = Convert.ToInt32(textBox2.Text); textBox2.Text = i.ToString();所以將它傳遞給.copies對我來說是一種麻煩,因爲它表示我隱式地將int傳遞給short,請幫助我如何將它傳遞給.copies – SoulShifter

回答

0

我沒有解決.copies問題,但還是老樣子不能在這裏解決的頁碼下,下面的代碼是我的代碼現在

private void button1_Click(object sender, EventArgs e) 
    { 
     short numCopies = 0; 
     numCopies = Convert.ToInt16(textBox2.Text); 


     PrintDocument printDocument = new PrintDocument(); 
     printDocument.DefaultPageSettings.Landscape = true; 
     printDocument.DefaultPageSettings.PaperSize = new PaperSize("zed", 400, 850); 
     printDocument.PrinterSettings.Copies = numCopies; 
     printDocument.PrintPage += PrintDocumentOnPrintPage; 
     printDocument.Print(); 

    }  
相關問題