gpt4 book ai didi

c# - 打印文档

转载 作者:太空狗 更新时间:2023-10-30 00:14:51 26 4
gpt4 key购买 nike

我想打印我的 TextBox,这是我的代码:

private void MenuItemPrint()
{
if (FileName != "")
{
PrintDocument document = new PrintDocument();
document.PrinterSettings.PrintFileName = FileName;
document.Print();
}
}

而且它不起作用。我该怎么办?

最佳答案

试试这个:

private void MenuItemPrint()
{
if (!FileName.Trim().Equals(""))
{
using(PrintDocument pd = new PrintDocument())
{
using(PrintDialog printDialog=new PrintDialog())
{
if(printDialog.ShowDialog()==DialogResult.Yes)
{
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
}
}
}
}
}
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
ev.Graphics.DrawString(FileName, new Font("Arial", 10), Brushes.Black,
ev.MarginBounds.Left, 0, new StringFormat());
}

关于c# - 打印文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20019265/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com