2011-10-27 6 views
2

격자 배열을 가지고 있으며 모든 grid.each 그리드를 그의 셀 텍스트 상자에 가지고 있습니다. 격자를 ShowGridLines = false;으로 설정하고 메소드에 텍스트 상자 테두리를 제거하십시오.GridLines없이 WPF 격자 인쇄

private void DeletBorder() 
{ 
    Thickness bor = new Thickness(0.0); 
    for (int i = 0; i < this.gridArray.Length; i++) 
    { 
     foreach (Control ctrl in this.gridArray[i].Children) 
     { 
      if (ctrl.GetType() == typeof(TextBox)) 
      { 
       ((TextBox) ctrl).BorderThickness = bor; 
      } 
     } 
    } 
} 

나는이 방법으로 배열에있는 모든 그리드를 인쇄하려고 :

private void button1_Click(object sender, RoutedEventArgs e) 
{ 
    if (this.comboBox1.SelectedIndex > -1) 
    { 
     PrintDialog printDlg = new PrintDialog(); 
     this.DeletBorder(); 
     if (printDlg.ShowDialog() == true) 
     { 
      this.DeletBorder(); 
      foreach (Grid item in this.gridArray) 
      { 
       printDlg.PrintVisual(item, "Stiker Print Job"); 
      } 
     } 
    } 
    else 
    { 
     MessageBox.Show("you must select the page layout first"); 
    } 
} 

하지만 결과는 첫 번째 페이지 테두리/눈금 선없이 인쇄하지만, 다른 하나는 여전히 테두리를 인쇄한다는 것입니다/gridLines

답변

1

첫 번째 문제는 this.DeleteBorder()을 두 번 호출하는 것이 의미가 없다는 것입니다.

두 번째로 gridArray에는 Grids가 있다고 가정합니다. 각 Grid.이 시도를 위해 당신이 어떤 눈금 선을 표시하지해야합니다

if (printDlg.ShowDialog() == true) 
{ 
    /* remove this--this.DeletBorder(); */ 

    int index = 0; 
    foreach(Grid item in this.gridArray) 
    { 
     item.ShowGridLines = false; 
     // Add an identifier so you know what job is printing. You may need to call: 
     // item.UpdateLayout(); 
     printDlg.PrintVisual(item, "Stiker Print Job: " + index.ToString()); 
    } 
} 

를이 문제가 해결되지 않으면, http://gist.github.com에 문제를 다시 일부 XAML 및/또는 그 이상의 샘플 코드를 제공하십시오.