有没有办法在MsChart中更改“打印预览”对话框的图标?

时间:2012-07-13 11:11:33

标签: c# mschart

我在Visual Studio 2010中使用C#4.0和MsCharts。当我执行

MyPlotChart.Printing.PrintPreview();

(请参阅http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.printingmanager.printpreview)它按预期工作,但“打印预览”对话框显示默认图标。有没有办法使用我自己的图标,好吗?就像我对PrintPreviewDialog.Icon所做的那样(见http://msdn.microsoft.com/en-us/library/system.windows.forms.printpreviewdialog.icon.aspx

感谢。

2 个答案:

答案 0 :(得分:1)

最后我为此写了一个黑客。我添加了一个在调用PrintPreview()之前启用的forms.timer。然后我在Application.OpenForms中找到该表单并设置图标。

    private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e)
    {
        if (PrintPreviewIcon != null)
        {
            PrintPreviewTimer.Enabled = true;
        }

        PlotChart.Printing.PrintPreview();
    }

    private void PrintPreviewTimer_Tick(object sender, EventArgs e)
    {
        foreach (Form f in Application.OpenForms)
        {
            if (f is PrintPreviewDialog)
            {
                f.Icon = PrintPreviewIcon;
                PrintPreviewTimer.Enabled = false;
            }
        }
    }

答案 1 :(得分:0)

我的回答,只需设置图标属性:

    public DialogResult ShowPrintPreview(float zoomFactor = 1F)
    {
        _nPageNumber = 1;
        _bPrintSel = false; 

        _previewDlg.PrintPreviewControl.Zoom = zoomFactor;
        _previewDlg.Size = new Size(1200, 800);
        _previewDlg.StartPosition = FormStartPosition.CenterScreen;

        _previewDlg.Icon = **PrintPreviewIcon**;
        return _previewDlg.ShowDialog(this);
    }

    public Icon PrintPreviewIcon { get; set; }