Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.2/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/ImageExportTool.cs @ 13398

Last change on this file since 13398 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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