C# .net windows 应用程序 - 打印文本框值

发布于 2024-08-31 04:49:54 字数 64 浏览 3 评论 0原文

我有两个文本框,当我在这些文本框中输入时,通过单击打印按钮,应该直接使用连接的打印机进行打印。谁能帮我我该怎么做?

I have two text boxes when i input in these text boxes , by clicking the print button , it should directly printed with the connected printer. can anybody help me how should i do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云归处 2024-09-07 04:49:54

下面的示例是使用/继承 PrintDocument 类的基本思想:

using System.Drawing.Printing;

public class PrintDoc : PrintDocument
{
    // there are other properties you can enter here
    // for instance, page orientation, size, font, etc.

    private string textout;

    public string PrintText
    {
        get { return textout; }
        set { textout = value; }
    }

    // you will also need to add any appropriate class ctor
    // experiment with the PrintDocument class to learn more
}

然后从表单的按钮事件中调用如下内容:

public void PrintDocument()
{
        //instance PrintDocument class
        PrintDoc printer = new PrintDoc();

        //set PrintText
        printer.PrintText = myTextBox.Text;

        printer.Print();    // very straightforward
}

The example below is a basic idea of using/inheriting the PrintDocument class:

using System.Drawing.Printing;

public class PrintDoc : PrintDocument
{
    // there are other properties you can enter here
    // for instance, page orientation, size, font, etc.

    private string textout;

    public string PrintText
    {
        get { return textout; }
        set { textout = value; }
    }

    // you will also need to add any appropriate class ctor
    // experiment with the PrintDocument class to learn more
}

Then from your form's button event, call something like:

public void PrintDocument()
{
        //instance PrintDocument class
        PrintDoc printer = new PrintDoc();

        //set PrintText
        printer.PrintText = myTextBox.Text;

        printer.Print();    // very straightforward
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文