1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using System.Windows.Forms;
|
---|
5 | using System.Drawing;
|
---|
6 | using System.IO;
|
---|
7 | using System.Drawing.Imaging;
|
---|
8 |
|
---|
9 | namespace 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 | }
|
---|