VB.NET 2008/VB - 인쇄

인쇄 - 특정 클라이언트 영역 인쇄 방법

본클라쓰 2012. 1. 3. 11:09

 

Windows Form의 지정한 클라이언트 영역을 인쇄하는 방법이다.

 

1. 새로운 폼을 하나 만든다.

2. 새로운 폼에 인쇄하고 싶은 부분을 지정하여 Panel이나 PictureBox 컨트롤로 영역을 지정한다.

 

 

 

3. 인쇄 버튼을 하나 만든 후 인쇄 버튼 클릭 이벤트 처리기를 작성하여 PrintDocument의 print 이벤트를 호출한다.

 

4. print 이벤트 처리기에 다음과 같은 코드를 작성한다.

 

' PictureBox1의 사이즈
Dim s As Size = Me.PictureBox1.Size

 

' Bitmap 개체를 생성한다. 
Dim img As Bitmap = New Bitmap(s.Width, s.Height, Me.PictureBox1.CreateGraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(img)

 

' PictureBox1의 화면상 위치
Dim p As Point = Me.PointToScreen(New Point(PictureBox1.Location.X, PictureBox1.Location.Y))

' img에 PictureBox1의 화면 캡쳐 이미지를 지정
memoryGraphics.CopyFromScreen(p.X, p.Y, 0, 0, s)

 

e.DrawImage(img, 0, 0)