2016-07-25 2 views
0

많은 바코드를 인쇄해야합니다. 나는 하나의 바코드를 인쇄하려면이 코드 블록을 사용하는 경우 어떻게 루프에서 작업을 수행 할 수 있습니다루프에서 많은 그래픽 개체를 인쇄하는 방법은 무엇입니까?

p.PrintPage += delegate(object sender1, PrintPageEventArgs e1) { 
        e1.Graphics.DrawString("TITLE", new Font("Univers 55", 6), new SolidBrush(Color.Black), new RectangleF(titleX, titleY, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height)); 
        e1.Graphics.DrawString(s, new Font("Barcode", 24), new SolidBrush(Color.Black), new RectangleF(codeX, codeY, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height)); 
        e1.Graphics.DrawString(test, new Font("Univers 55", 8), new SolidBrush(Color.Black), new RectangleF(numberX, numberY, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height)); 

을};

titleX, titleY, 분과, codeY, numberX, numberY 각 바코드 객체의 세 부분 (제목, 줄무늬 번호)의 위치를 ​​저장하는 변수이다, 이들은 루프에서 스스로 변경해야합니다.

+1

함수에 넣고 함수를 루프로 호출 하시겠습니까? –

답변

2

하나의 페이지에 여러 개의 바코드를 인쇄하려는 경우 루프에 넣지 못하게하는 방법은 없습니다. 한 페이지에 들어갈 것보다 더 많은 경우

p.PrintPage += PrintPage; 
... 
private void PrintPage(object sender, PrintPageEventArgs e) 
{ 
    for (int i = 0; i < numberOfBarcodes; i++) 
    { 
     int titleY = i * titleYdistance + titleYoffset; 
     // etc. 

     e.Graphics.DrawString(...); 
     // etc. 
    } 
} 

에서, PrintPageEventArgs 클래스는 HasMorePages을 가지고 : 나는 깨끗하게 유지하는 대신 "인라인 대표"의,하지만 별도의 방법에 코드를 이동할 것 재산. 이 속성을 true으로 설정하면 각 페이지마다 다른 바코드를 인쇄 할 수 있으므로 이벤트 메서드가 호출됩니다.

+0

감사! 나는 여전히 그것을 시도하고있다 :) – relapse

+0

'HasMorePages' 속성이 작동하지 않는다. 어디에서 설정해야합니까? – relapse

+0

@relapse "그냥 설정"하지 않으면 모든 것을 단일 페이지에 넣을 수 있는지 알아 내야합니다. 'true'로 설정하고 루프에서 일찍 탈출 할 수 없다면 알아낼 필요가 있습니다. 그러면 함수가 두 번째 페이지에 대해 다시 호출됩니다. 인쇄 할 바코드가 부족할 때까지 해당 프로세스를 반복 한 다음 false로 설정합니다. 방법에 대한 예제는 [방법 : Windows Forms에서 여러 페이지 텍스트 파일 인쇄] (https://msdn.microsoft.com/en-us/library/cwbe712d(v=vs.110).aspx)를 참조하십시오. 마지막으로'i'를 기억하고 그 +1을 시작점으로 사용할 때마다'i'가'0'으로 변합니다. –

관련 문제