2012-04-21 3 views
0

오른쪽면 여백을 유지하기 위해 수평 위치에 페이지를 추가하려고합니다. 또는 x 위치가 카운터보다 큽니다. 코드를 실행하면 무한 루프로 끝나고 수백 페이지가 모두 같은 첫 페이지 그래픽을 표시합니다. 생각하면 HasMorePages에 대한 이해가 부족할 수도 있습니다. 나는 약간의 도움을 사용할 수있다. 감사.수평 위치에 새 페이지를 만들려고합니다. 내가 오른쪽 상단 여백을 연장합니다.

public static class PrintWave 
{ 
    public static void PrintPreWave() 
    { 

     PrintDocument pd = new PrintDocument(); 

     if (WaveTools.MySettings == null) 
     { 
      pd.DefaultPageSettings.Landscape = true; 
     } 
     else 
     { 
      pd.DefaultPageSettings = WaveTools.MySettings; 
     } 
     pd.OriginAtMargins = true; 

     pd.PrintPage += new PrintPageEventHandler(OnPrintPage); 
     PrintDialog dlg = new PrintDialog(); 
     PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog(); 
     printPreviewDlg.Document = pd; 

     Form p = (Form)printPreviewDlg; 
     p.WindowState = FormWindowState.Maximized; 
     printPreviewDlg.ShowDialog(); 


    } 

    private static void OnPrintPage(object sender, PrintPageEventArgs e) 
    { 
     string MyTag = string.Empty; 
     MyTag = WaveActions.ActiveId; 
     Wave MyWave = WaveHolder.FindWave(MyTag); 
     int MyCount = 0; 

     int xOffset = e.MarginBounds.Location.X; 

     int yOffset = e.MarginBounds.Location.Y; 


     if (MyWave != null) 
     { 
      Graphics g = e.Graphics; 
      g.SetClip(e.PageBounds); 

      Pen MyPen = new Pen(WaveTools.WaveColor, WaveTools.PenWidth); 

      float dx = (float)e.PageBounds.Width/MyWave.NumSamples; 
      float dy = (float)e.PageBounds.Height/255; 


      if (MyWave.Normal == false) 
      { 
       g.ScaleTransform(dx, dy); 

      } 



      for (int i = 0; i < MyWave.NumSamples - 1; i++) 
      { 





       g.DrawLine(MyPen, i, MyWave.Data[i], i + 1, MyWave.Data[i + 1]); 
       MyCount = MyCount + 1; 

       if (MyCount > e.MarginBounds.Width) 
       { 

        e.HasMorePages = true; 
        MyCount = 0; 
        return; 
       } 
       else 
       { 

        e.HasMorePages = false; 
        return; 

       } 


      } 


     } 


    } 

} 

} 핵심 문제 문을의

답변

1
 for (int i = 0; i < MyWave.NumSamples - 1; i++) 

, 당신은 0에서 PrintPage가 호출 될 때마다 시작합니다. 이력서 이전 페이지에서 중단 한 부분이 필요합니다. i 변수를 로컬 변수 대신 클래스의 필드로 만듭니다. BeginPrint 이벤트를 구현하여 0으로 설정하십시오.

루프 내의 else 절을 ​​삭제해야합니다.

+0

그게 전부입니다. 그것은 재귀입니다. 도와 주셔서 정말로 고맙습니다. –

+0

재귀는 아니며 각 페이지에 대해 동일한 이벤트 핸들러를 반복적으로 호출합니다. 답을 표시하여 질문을 닫으십시오. –

관련 문제