Skip to content

Commit 9b8da48

Browse files
author
Oystein Bjorke
authored
Merge pull request oxyplot#1298 from rusamentiaga/winforms-copy-command
Winforms copy command
2 parents 0148516 + d852fc4 commit 9b8da48

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
99
- New PolarPlot filling the full plot area (#1056)
1010

1111
### Added
12+
- Command to copy plot to the clipboard in Windows Forms (Ctrl-C) (#1297)
1213
- Added Avalonia based renderer and control library (based off OxyPlot.Wpf).
1314
- New `InterpolationAlgorithm` property in LineSeries and PolylineAnnotation (#494)
1415
- Catmull-Rom spline interpolation algorithms (#494)

CONTRIBUTORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,5 @@ Xavier <Xavier@xavier-PC.lsi>
118118
zur003 <Eric.Zurcher@csiro.au>
119119
Markus Ebner
120120
Duncan Robertson <duncanjacobrobertson@gmail.com>
121-
LauXjpn <laucomm@gmail.com>
121+
LauXjpn <laucomm@gmail.com>
122+
R. Usamentiaga

Source/OxyPlot.WindowsForms/PlotView.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public PlotView()
9898
this.ZoomRectangleCursor = Cursors.SizeNWSE;
9999
this.ZoomHorizontalCursor = Cursors.SizeWE;
100100
this.ZoomVerticalCursor = Cursors.SizeNS;
101+
102+
var DoCopy = new DelegatePlotCommand<OxyKeyEventArgs>((view, controller, args) => this.DoCopy(view, args));
103+
this.ActualController.BindKeyDown(OxyKey.C, OxyModifierKeys.Control, DoCopy);
101104
}
102105

103106
/// <summary>
@@ -552,5 +555,27 @@ private static OxyModifierKeys GetModifiers()
552555

553556
return modifiers;
554557
}
558+
559+
/// <summary>
560+
/// Performs the copy operation.
561+
/// </summary>
562+
private void DoCopy(IPlotView view, OxyInputEventArgs args)
563+
{
564+
var background = this.ActualModel.Background.IsVisible() ? this.ActualModel.Background : this.ActualModel.Background;
565+
if (background.IsInvisible())
566+
{
567+
background = OxyColors.White;
568+
}
569+
570+
var exporter = new PngExporter
571+
{
572+
Width = this.ClientRectangle.Width,
573+
Height = this.ClientRectangle.Height,
574+
Background = background
575+
};
576+
577+
var bitmap = exporter.ExportToBitmap(this.ActualModel);
578+
Clipboard.SetImage(bitmap);
579+
}
555580
}
556-
}
581+
}

0 commit comments

Comments
 (0)