Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to paste metafile of Control's image to the Clipboard in C#?

I would like to know how to paste metafile of Control's image into the Clipboard using C#.

I've succeeded in Bitmap format as follow, althoguh the image size is very large.

Bitmap theBitmap = new Bitmap(this.axCWGraph.ControlImage());
Clipboard.SetDataObject(theBitmap);

However, I have no idea how to deal with metafile.
0 Kudos
Message 1 of 5
(8,910 Views)
There is a Metafile class in the .NET framework that you can use to work with metafiles. Like Bitmap, it derives from Image, so much of the API is similar. Many of the methods of the Graphics class work with Image rather than Bitmap, though, so you can use Bitmap and Metafile interchangeably with these methods. For example, here is an example of how you can resize the metafile and copy the resized metafile to the clipboard:

void CopyGraphToClipboard(AxCWGraph graph, int width, int height)
{
using (Image controlImage = graph.ControlImage())
using (Bitmap clipboardImage = new Bitmap(width, height))
using (Graphics g = Graphics.FromImage(clipboardImage))
{
g.DrawImage(controlImage, 0, 0, width, height);
Clipboard.SetDataObject(clipboardImage, true);
}
}


To copy an image of the graph to the clipboard whose width is 400 and height is 300, you can call this method like this:

CopyGraphToClipboard(axCWGraph, 400, 300);


Just out of curiosity, is there a reason that you're using the interop wrappers for the Measurement Studio ActiveX graph instead of using the native Measurement Studio .NET Windows Forms graph? The Measurement Studio .NET Windows Forms graph controls have a method called ToClipboard that will copy an image of the graph to the clipboard with the specified size. For example, the snippets above would look like this instead:

graph.ToClipboard(new Size(400, 300));


- Elton
0 Kudos
Message 2 of 5
(8,899 Views)
1. Thank you very much Elton. I could copy my bitmap image into clipboard succesfully.

2. I tried to do with Metafile as you recommanded. However, Metafile constructor is not as simple as Bitmap constructor. I could not understand why I should pass stream, hDc and so on into metafile. I just want to copy my graph into clipboard and paste into Office files. Moreover, I hope to resize my pasted image without loosing image quality. Could you teach me how can I achive my purpose?

3. I do not use .NET Graph since it does not support Korean Language correctly. I attached example image which shows two graphs. You may notice Y-Axis caption are not the same although I tried to write same characters. DotNET graph rotates y-axis caption incorrectly.
0 Kudos
Message 3 of 5
(8,886 Views)
Hello,

Here is the URL to a site that I found on MSDN called, "Saving Image to Bitmap or Clipboard":

http://www.proworks.com/help/FlipperGraphControl/Saving_Image_to_Bitmap_or_C.htm

If this is not what you are looking for, you can find help about Visual Studio issues by searching www.msdn.com.


Regards,

Aaron B.
National Instruments
0 Kudos
Message 4 of 5
(8,799 Views)
Please ignore the previous post. The site I had found relates to specific controls for another API and does not apply to Measurement Studio controls. I would highly recommend looking on MSDN and google newsgroups to see how to set up meta files with the clipboard using MFC. Take care!

http://msdn.microsoft.com/

Regards,

Aaron B.
National Instruments
0 Kudos
Message 5 of 5
(8,787 Views)