c# - 在 C# 中打印文本框内容

标签 c# winforms

我想打印一个简单文本框的内容。单击打印按钮后,将显示 PrintDialog。

我找到了很多信息,但他们都使用 RichTextBoxes。有没有一种简单的方法可以做类似 this 的事情?

最佳答案

此打印名为 textbox1textbox 的内容

    PrintDocument document = new PrintDocument();
    PrintDialog dialog = new PrintDialog();
    public Form1()
    {
        InitializeComponent();
        document.PrintPage += new PrintPageEventHandler(document_PrintPage);
    }

    void document_PrintPage(object sender, PrintPageEventArgs e)
    {
        e.Graphics.DrawString(textBox1.Text, new Font("Arial", 20, FontStyle.Regular), Brushes.Black, 20, 20);
    }

    private void btnPrint_Click(object sender, EventArgs e)
    {
        dialog.Document = document;
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            document.Print();
        }
    }

关于c# - 在 C# 中打印文本框内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18547862/

相关文章:

c# - super 模糊名称检查?

C# ASP.NET 用户控件 如何处理 div 单击服务器端?

c# - 表格 "Not responding"如果之前没有显示

c# - 使用 DataGridView 在另一个窗体的 TextBox 中显示数据库信息

vb.net - 如何以编程方式按下网站的登录按钮

windows - 此文件位于本地网络之外的位置

c# - Azure 表随机返回 null 值

c# - NLOG 和 Azure 表存储

c# - 使用 Swashbuckle 5.x 在通用 T 参数引用属性上指定 nullable = true

C# 将表单中的数据插入访问数据库