How to print the contents of a TextBox

后端 未结 3 638
臣服心动
臣服心动 2021-01-04 05:29

How do I print the contents of a TextBox in metro apps? I have read this quickstart guide on MSDN and many online tutorials, but they are very complicated and do not

3条回答
  •  梦谈多话
    2021-01-04 05:49

    I just created a small winforms-application with a textbox (textBox1) and a button (button1). The code-behind looks like:

    public partial class Form1 : Form
    {
        public Form1()
        {
               InitializeComponent();
        }
    
        private void PrintDocumentOnPrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawString(this.textBox1.Text, this.textBox1.Font, Brushes.Black, 10, 25);
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            PrintDocument printDocument = new PrintDocument();
            printDocument.PrintPage += PrintDocumentOnPrintPage;
            printDocument.Print();
        }
    }
    

    On a click on the button the printing will be done.

提交回复
热议问题