开发者

C# .net windows application - Printing Text Box Values

开发者 https://www.devze.com 2022-12-29 03:40 出处:网络
I have two text boxes when i input in these text boxes , by clicking the print button , it should directly printed with the 开发者_C百科connected printer. can anybody help me how should i do this?The

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


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号