//*************************************************************************
        //  Constructor: AutomatedGraphImageUserSettingsDialog()
        //
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="AutomatedGraphImageUserSettingsDialog" /> class.
        /// </summary>
        ///
        /// <param name="automatedGraphImageUserSettingsUserSettings">
        /// The object being edited.
        /// </param>
        //*************************************************************************
        public AutomatedGraphImageUserSettingsDialog(
            AutomatedGraphImageUserSettings
            automatedGraphImageUserSettingsUserSettings
            )
        {
            Debug.Assert(automatedGraphImageUserSettingsUserSettings != null);
            automatedGraphImageUserSettingsUserSettings.AssertValid();

            m_oAutomatedGraphImageUserSettings =
            automatedGraphImageUserSettingsUserSettings;

            // Instantiate an object that saves and retrieves the position of this
            // dialog.  Note that the object automatically saves the settings when
            // the form closes.

            m_oAutomatedGraphImageUserSettingsDialogUserSettings =
            new AutomatedGraphImageUserSettingsDialogUserSettings(this);

            InitializeComponent();
            DoDataExchange(false);

            AssertValid();
        }
Beispiel #2
0
        //*************************************************************************
        //  Method: SaveGraphImageFile()
        //
        /// <summary>
        /// Save an image of the graph to a file.
        /// </summary>
        ///
        /// <param name="oNodeXLControl">
        /// The control that displays the graph.
        /// </param>
        ///
        /// <param name="sWorkbookFilePath">
        /// Path to the workbook file.  Sample: "C:\Workbooks\TheWorkbook.xlsx".
        /// </param>
        ///
        /// <remarks>
        /// The settings stored in the AutomatedGraphImageUserSettings class are
        /// used to save the image.
        /// </remarks>
        //*************************************************************************
        private static void SaveGraphImageFile(
            NodeXLControl oNodeXLControl,
            String sWorkbookFilePath
            )
        {
            Debug.Assert(oNodeXLControl != null);
            Debug.Assert( !String.IsNullOrEmpty(sWorkbookFilePath) );

            AutomatedGraphImageUserSettings oAutomatedGraphImageUserSettings =
            new AutomatedGraphImageUserSettings();

            Size oImageSizePx = oAutomatedGraphImageUserSettings.ImageSizePx;

            Bitmap oBitmapCopy = oNodeXLControl.CopyGraphToBitmap(
            oImageSizePx.Width, oImageSizePx.Height);

            ImageFormat eImageFormat =
            oAutomatedGraphImageUserSettings.ImageFormat;

            String sImageFilePath = Path.ChangeExtension( sWorkbookFilePath,
            SaveableImageFormats.GetFileExtension(eImageFormat) );

            try
            {
            oBitmapCopy.Save(sImageFilePath, eImageFormat);
            }
            catch (System.Runtime.InteropServices.ExternalException)
            {
            // When an image file already exists and is read-only, an
            // ExternalException is thrown.
            //
            // Note that this method is called from the
            // ThisWorkbook.GraphLaidOut event handler, so this exception can't
            // be handled by a TaskAutomator.AutomateThisWorkbook() exception
            // handler.

            FormUtil.ShowWarning( String.Format(
                "The image file \"{0}\" couldn't be saved.  Does a read-only"
                + " file with the same name already exist?"
                ,
                sImageFilePath
                ) );
            }
            finally
            {
            oBitmapCopy.Dispose();
            }
        }
        //*************************************************************************
        //  Method: btnSaveGraphImageFile_Click()
        //
        /// <summary>
        /// Handles the Click event on the btnSaveGraphImageFile button.
        /// </summary>
        ///
        /// <param name="sender">
        /// Standard event argument.
        /// </param>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        //*************************************************************************
        private void btnSaveGraphImageFile_Click(
            object sender,
            EventArgs e
            )
        {
            AssertValid();

            AutomatedGraphImageUserSettings oAutomatedGraphImageUserSettings =
            new AutomatedGraphImageUserSettings();

            AutomatedGraphImageUserSettingsDialog
            oAutomatedGraphImageUserSettingsDialog =
            new AutomatedGraphImageUserSettingsDialog(
                oAutomatedGraphImageUserSettings);

            if (oAutomatedGraphImageUserSettingsDialog.ShowDialog() ==
            DialogResult.OK)
            {
            oAutomatedGraphImageUserSettings.Save();
            }
        }