How to copy a plot in WindowsForms ?

Oystein Bjorke 4 years ago 0
This discussion was imported from CodePlex

buaashuai wrote at 2014-07-03 13:46:

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.

Slxe wrote at 2014-07-04 19:27:

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.

buaashuai wrote at 2014-07-06 10:01:

Thanks to you. you answer is right and my problem has solved.

buaashuai wrote at 2014-07-06 10:02:

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.
CodePlex