How to copy a plot in WindowsForms ?

Jul 3, 2014 at 12:46 PM
Hi~~ I am using WindowsForms, and i need to copy a plot to clipboard after i press a button. In what way can i accomplish this? Thanks.
Jul 4, 2014 at 6:27 PM
Here's how I'm handling it:
PlotController.BindKeyDown(OxyKey.C,
                           OxyModifierKeys.Control,
                           new DelegatePlotCommand<OxyKeyEventArgs>(
                               CopyChart_OnKeyDown));
                               
private void CopyChart_OnKeyDown(
    IPlotView view,
    IController controller,
    OxyKeyEventArgs args)
{
    var chartBitmap = new Bitmap(uiPlotView.Width, uiPlotView.Height);
    uiPlotView.DrawToBitmap(chartBitmap,
                            new Rectangle(0, 0, uiPlotView.Width, uiPlotView.Height));
    Clipboard.SetImage(chartBitmap);
}
I actually based this on some code that used to be in the PlotCommands, not sure why it was taken out.
Marked as answer by buaashuai on 7/6/2014 at 1:02 AM
Jul 6, 2014 at 9:01 AM
Thanks to you. you answer is right and my problem has solved.
Jul 6, 2014 at 9:02 AM
Slxe wrote:
Here's how I'm handling it:
PlotController.BindKeyDown(OxyKey.C,
                           OxyModifierKeys.Control,
                           new DelegatePlotCommand<OxyKeyEventArgs>(
                               CopyChart_OnKeyDown));
                               
private void CopyChart_OnKeyDown(
    IPlotView view,
    IController controller,
    OxyKeyEventArgs args)
{
    var chartBitmap = new Bitmap(uiPlotView.Width, uiPlotView.Height);
    uiPlotView.DrawToBitmap(chartBitmap,
                            new Rectangle(0, 0, uiPlotView.Width, uiPlotView.Height));
    Clipboard.SetImage(chartBitmap);
}
I actually based this on some code that used to be in the PlotCommands, not sure why it was taken out.
Thanks to you. you answer is right and my problem has solved.