Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/ImageExportTool.cs @ 2768

Last change on this file since 2768 was 2768, checked in by mkommend, 14 years ago

added solution folders and sources for the netron library (ticket #867)

File size: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Windows.Forms;
5using System.Drawing;
6using System.IO;
7using System.Drawing.Imaging;
8
9namespace Netron.Diagramming.Core
10{
11    // ----------------------------------------------------------------------
12    /// <summary>
13    /// A tool that uses the ImageExporter to create an image from the
14    /// currently selected entities and adds the image to the clipboard.
15    /// The ImageExporter is used indirectly by calling
16    /// 'Selection.ToBitmap()'.
17    /// </summary>
18    // ----------------------------------------------------------------------
19    public class ImageExportTool : AbstractTool
20    {
21        // ------------------------------------------------------------------
22        /// <summary>
23        /// Initializes a new instance of the <see cref="T:ImageExportTool"/>
24        /// class.
25        /// </summary>
26        /// <param name="name">string: The name of the tool.</param>
27        // ------------------------------------------------------------------
28        public ImageExportTool(string toolName)
29            : base(toolName)
30        {
31        }
32
33        #region Methods
34
35        // ------------------------------------------------------------------
36        /// <summary>
37        /// Called when the tool is activated.
38        /// </summary>
39        // ------------------------------------------------------------------
40        protected override void OnActivateTool()
41        {
42            if (Selection.SelectedItems.Count == 0)
43            {
44                MessageBox.Show("No shapes are selected.  " +
45                    "Please make a selection first.",
46                    "Image Export Error",
47                    MessageBoxButtons.OK,
48                    MessageBoxIcon.Information);
49                return;
50            }
51
52            try
53            {
54                // Create an image using the ImageExporter and copy it to
55                // the clipboard.
56                Bitmap image = Selection.ToBitmap();
57                if (image != null)
58                {                   
59                    Clipboard.SetImage(image);
60                }
61            }
62            catch (Exception exc)
63            {
64                throw new InconsistencyException(
65                    "The Copy operation failed.", exc);
66            }
67            finally
68            {
69                DeactivateTool();
70            }
71        }
72
73        #endregion
74    }
75}
Note: See TracBrowser for help on using the repository browser.