Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
i have form as bill and i want to print it as it self
Posted
Comments
venkateshCST 9-Aug-13 5:58am    
If you are using Windows form then it helps u,if any quiries let me know...
http://www.c-sharpcorner.com/uploadfile/mgold/pritingincsharp11222005040630am/pritingincsharp.aspx
Rabee3-F1.787545 9-Aug-13 6:03am    
it is not a text file i want to take a snap shot
and print it
Rabee3-F1.787545 9-Aug-13 6:02am    
it is not a text file i want to capture the form and print it with all components

1 solution

may I suggest msdn approach?

C#
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;

public class Form1 :
    Form
{
    private Button printButton = new Button();
    private PrintDocument printDocument1 = new PrintDocument();

    public Form1()
    {
        printButton.Text = "Print Form";
        printButton.Click += new EventHandler(printButton_Click);
        printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
        this.Controls.Add(printButton);
    }

    void printButton_Click(object sender, EventArgs e)
    {
        CaptureScreen();
        printDocument1.Print();
    }


    Bitmap memoryImage;

    private void CaptureScreen()
    {
        Graphics myGraphics = this.CreateGraphics();
        Size s = this.Size;
        memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
        Graphics memoryGraphics = Graphics.FromImage(memoryImage);
        memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
    }

    private void printDocument1_PrintPage(System.Object sender,  
           System.Drawing.Printing.PrintPageEventArgs e)
    {
        e.Graphics.DrawImage(memoryImage, 0, 0);
    }



    public static void Main()
    {
        Application.Run(new Form1());
    }
}
 
Share this answer
 
Comments
Rabee3-F1.787545 9-Aug-13 7:28am    
Thank You It Is very Useful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900