주니봉
  • winform 화면 프린팅
    2015년 10월 19일 11시 36분 00초에 업로드 된 글입니다.
    작성자: 봉주니
    public class Form1 : Form
    {
        private Button printButton = new Button();
        private PrintDocument printDocument1 = new PrintDocument();
    
        public Form1()
        {
            printButton.Text = "Print Form";
            printButton.Click += printButton_Click;
            printDocument1.PrintPage += 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(Location.X, 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());
        }
    }


    반응형
    댓글