Active2 years, 3 months ago
  1. Sharp Copy Machine Toner
  2. Sharp
  3. Sharp Copy Machine Manual

I am learning C# as I write a program which interfaces with a spectrometer. I have figured out how to get a spectrum from the spectrometer and plot it on an MS chart.

How do I copy the contents of a String to the clipboard in C#? Read a random line from file on webserver and add to clipboard. How to copy data to clipboard.

Copy

How do I copy the image of the chart into the clipboard so that it can be pasted into other programs?

I'm using Visual Studio C# 2010.

I have found the chart.SaveImage method, but I would really rather copy the image to the clipboard rather than having to save it to disk. I have not found a chart.CopyPicture method.

I also figured out how to copy the raw data to clipboard as a string, which can then be pasted into an Excel worksheet and plotted, but I would rather just copy the image itself.

Additonal data:

I am able to copy the image to the clipboard using the following code:

Surely there is way to get the image directly Clipboard without saving and retrieving it from a disk file first. Please, please let me know how this is done (before one of my coworkers finds this kludge)!

Curt
Curt

Sharp Copy Machine Toner

Curt
6344 gold badges10 silver badges21 bronze badges

3 Answers

To get image from chart control, save it to memory stream, create bitmap and then send it to clipboard:

C Sharp Copy File Clipboard
pasconpascon
Tim JarvisTim Jarvis
14.7k8 gold badges49 silver badges85 bronze badges

I am saving the chart images as a metafile (EMF) through a memory stream. I want to preserve the original image resolution and preserve the option to ungroup the vector images and edit them in PowerPoint. Recently, I upgraded to a very high-resolution laptop and I found that the chart image was being framed with a lot of empty space. If I paste the image into PowerPoint or Word, the pasted image will be very small. Cropping and resizing manually is not satisfactory, and I don't want to have to downgrade my screen resolution to get the images to paste larger. Here is the solution I found (below).

I am using VB.Net 2008, so the Chart.Clone method was not available. I had to implement a separate function to clone the chart, but if you have a more recent version of Visual Studio, you can uncomment the line below and delete the CloneMSChart function and the line referencing it. Here are references to the relevant websites I used to find the solution:

and here is the composite solution:

'-------------------------------------------------------------

'------------------------------------------------------------

'-------------------------------------------------------

Sharp

Robert CodyRobert Cody

Sharp Copy Machine Manual

Not the answer you're looking for? Browse other questions tagged c#.netcharts or ask your own question.