[英]Print WPF grid without GridLines
我有網格數組,我想打印所有網格。每個網格在他的單元格文本框中都有設置為ShowGridLines = false;
的網格ShowGridLines = false;
而且我有一個方法刪除文本框邊框。
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");
}
}
但是結果是只有第一頁打印時沒有border / gridLines,而另一頁仍然打印有border / gridLines
第一個問題是,兩次調用this.DeleteBorder()
是沒有意義的。
其次,假設gridArray
中僅包含Grid
。 您無需為每個Grid.
顯示任何網格線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和/或更多示例代碼以重新創建問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.