Search code examples
c#mschart

Is there a way to change the icon of the PrintPreview dialog in MsChart?


I'm using C# 4.0 and MsCharts within Visual Studio 2010. When I execute

MyPlotChart.Printing.PrintPreview();

(See http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.printingmanager.printpreview ) It works as intended, but the Print Preview dialog shows the default icon. Is there a way to use my own icon, please? Like what I would do with PrintPreviewDialog.Icon (see http://msdn.microsoft.com/en-us/library/system.windows.forms.printpreviewdialog.icon.aspx )

Thanks.


Solution

  • In the end I wrote a hack for this. I added a forms.timer that I enable right before calling PrintPreview(). Then I locate the form in Application.OpenForms and set the icon.

        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;
                }
            }
        }