C#
C# -- 인쇄 #3 -- printing preview
자유프로그램
2015. 8. 17. 18:00
반응형
C# -- 인쇄 #3 -- printing preview
개발환경 : visual studio 2013, windows 7 64bit
참고 : C#을 이용한 윈도우 폼 프로그래밍, 초판 p.278~281
https://msdn.microsoft.com/ko-kr/library/System.Windows.Forms.PrintPreviewControl(v=vs.110).aspx
http://www.whiteboardcoder.com/2013/05/visual-studio-2012-c-printpreviewcontrol.html
** Winform 설정
-- Toolbox 에서 PrintDocument 컨트롤과 PrintPreviewControl 컨트롤을 폼에 드래그 한다.
** 코드
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Drawing; | |
using System.Windows.Forms; | |
namespace printer_test2 | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
// 미리보기 | |
printPreviewControl1.Document = printDocument1; | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
// 인쇄 시작 명령... | |
printPreviewControl1.Document.Print(); | |
} | |
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) | |
{ | |
Graphics g = e.Graphics; | |
PointF drawPoint = new PointF(150.0F, 150.0F); // 좌측 상단 시작점. | |
// 2중 using 문 사용. | |
using (Font font = new Font("Lucida Console", 30)) | |
using (SolidBrush drawBrush = new SolidBrush(Color.Black)) | |
{ | |
g.DrawString("printPreviewControl test.....\n printer", font, drawBrush, drawPoint); | |
} | |
} | |
} | |
} |
** 결과물
--- 인쇄 버튼 누르면 인쇄됨...
반응형