我發現打印代碼。但我想在沒有對話框的情況下自動發送到打印機。我知道printername。我從SQL表中獲取打印機名稱。我該怎麼做 ?不帶對話框自動打印
// select printer and get printer settings
PrintDialog pd = new PrintDialog();
if (pd.ShowDialog() != true) return;
// create a document
FixedDocument document = new FixedDocument();
document.DocumentPaginator.PageSize = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight);
// create a page
FixedPage page1 = new FixedPage();
page1.Width = document.DocumentPaginator.PageSize.Width;
page1.Height = document.DocumentPaginator.PageSize.Height;
// add some text to the page
TextBlock page1Text = new TextBlock();
page1Text.Text = "This is a text"
page1Text.FontSize = 12; // 30pt text
page1Text.Margin = new Thickness(50); // 1 inch margin
page1.Children.Add(page1Text);
// add the page to the document
PageContent page1Content = new PageContent();
((IAddChild)page1Content).AddChild(page1);
document.Pages.Add(page1Content);
// and print
pd.PrintDocument(document.DocumentPaginator, "Print");
如果刪除if(pd.ShowDialog()!= true),會發生什麼情況; '線? –
查看'PrintDocument'類:http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument(v=vs.110).aspx – Treb
謝謝默認語言環境。但是希望在Windows上使用不默認的打印機。我想使用我知道打印機名稱的打印機。 – user2550719