Click here to Skip to main content
14,972,737 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i'm using a Picturebox and a Richtextbox.
copy Image from Picturebox in Clipboad with this Code:
C#
Clipboard.Clear();
Clipboard.SetImage(pictureBox1.Image);

and Paste Image from Clipboard to Richtextbox with this Code:
DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap);
if (richTextBox1.CanPaste(myFormat))
    {
        richTextBox1.Paste(myFormat);
    }
else
    {
        MessageBox.Show("The data format that you attempted to paste is not supported by this    control.");
    }


but when Paste image from Clipboard to Richtextbox, Color Background image is Blue!
See this Image:
http://uploadpic.ir/up/images/2pfp.jpg[^]

So How change Color Background of Clipboard?

GoodLuck
Posted
Updated 14-Mar-13 10:30am
v3
Comments
[no name] 14-Mar-13 7:53am
   
The clipboard does not have a color. And whatever that site is that you link to does not demonstrate your problem.
Sergey Alexandrovich Kryukov 14-Mar-13 16:44pm
   
My 5! However, the problem is solvable, but the method is dirty.
I provided detailed answer, with good and interesting alternatives, please see.
Your comment is of course credited.
—SA
Menon Santosh 14-Mar-13 9:37am
   
You can not change the color of any object on clipboard
alias136792 14-Mar-13 12:24pm
   
i whant just copy image from Picturebox to Richtextbox.
but when copy to Richtextbox, Image backcolor is blue! i want change this color to white.
so what i do?
Sergey Alexandrovich Kryukov 14-Mar-13 16:45pm
   
Nevertheless, the problem is solvable, even with this (dirty!) clipboard method. Please see my answer.
—SA
Adam David Hill 14-Mar-13 14:31pm
   
The link you have given us needs a password to the forum. Please can you send a direct link to the image which is not password protected?
Adam David Hill 14-Mar-13 14:32pm
   
I'm guessing here as I can't see the screenshot, but is your image by any chance part-transparent and PNG format? This sounds like it could be a control or framework which does not fully support the PNG format, and defaults in a background colour.
alias136792 14-Mar-13 16:31pm
   
i update link image.
Adam David Hill 14-Mar-13 16:34pm
   
It looks like the row highlight for that element. If you click on the text saying "RickTextBox" above it does it move to that?
Sergey Alexandrovich Kryukov 14-Mar-13 16:45pm
   
The problem is solvable, even with this (dirty!) clipboard method. Please see my answer.
—SA

1 solution

As ThePhantomUpvoter correctly pointed out, the clipboard has no color. :-)

You need to change the background of the image before you copy it with Clipboard.SetImage. Then you can restore it.

If you use the clipboard just to put data in the rich text box, this is a very dirty method, because you interfere with other possible uses of the clipboard. You can write to rich text box content directly, using its format, which is publicly available:
http://en.wikipedia.org/wiki/Rich_Text_Format[^],
http://www.microsoft.com/en-us/download/details.aspx?id=10725[^].

I remember one answer of one CodeProject member who demonstrated the code doing it. However, I don't want to search for this CodeProject link. First, you can do it by yourself. More importantly, RTF format is very awkward to work with and pretty much obsolete. I would advise to use something else: HTML, Microsoft Office Open XML or open-source OpenDocument:
http://en.wikipedia.org/wiki/Open_XML[^],
http://en.wikipedia.org/wiki/OpenDocument[^].

The standards are well documented, there are APIs you can use. Interested?

Now, as to HTML. There is a perfect CodeProject component which will render HTML document for you, without using the WebBrowser control. You can even use hrefs to embedded resources, including images. Please see:
A Professional HTML Renderer You Will Use[^].

By the way, you don't need PictureBox at all. You need a bitmap (in other cases, you need direct rendering of graphics). Why you guys always use this nearly useless control, even in cases when it does not help at all, only presents hassles?!

—SA
   
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900