Copying graphic contents of picturebox/panel to clipboard

Gizmo001

Active member
Joined
Dec 27, 2002
Messages
33
How do you copy the graphic contents of a panel or picturebox to the clipboard? The contents were prepared using createGraphics from System.Drawing.Graphics.
 
I dont have a problem posting a textbox or another control. I would like to post the entire graphic contents to the clipboard to paste in PowerPoint/Word/WordPerfect without changes in relative locations of the graphics.

Thanks.
 
Assuming youre drawing to the Image portion of the pictureBox, you could try something like this:

Code:
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics g = Graphics.FromImage(pictureBox1.Image);
g.DrawLine(Pens.Red, 0, 0, 20, 20);
g.Dispose();
Clipboard.SetDataObject(pictureBox1.Image, true);

The first line creates a new Bitmap for the Image property.
The next few lines simulate some drawing to the Image property (a simple red line in this case).
The last line saves the bitmap to the clipboard, which is what I think you were asking...?

-ner
 
Back
Top