【问题标题】:Print WPF grid without GridLines打印没有 GridLines 的 WPF 网格
【发布时间】:2011-10-27 14:52:56
【问题描述】:

我有网格数组,我想打印所有网格。每个网格在他的单元格文本框中都有 网格设置为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");
    }
}

但结果是只有第一页打印没有边框/网格线,而另一页仍然打印有边框/网格线

【问题讨论】:

    标签: c# wpf printing printdialog


    【解决方案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());
        }
    }
    

    如果这不能解决您的问题,请提供一些 XAML 和/或更多示例代码以在 http://gist.github.com 上重新创建问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-05
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多