Home > DeveloperSection > Forums > How can I insert an Image in RichTextBox using C#?
Kate Smith
Kate Smith

Total Post:24

Points:168
Posted on    September-28-2013 8:15 AM

 C# C# 
Ratings:


 1 Reply(s)
 6090  View(s)
Rate this:

I'm trying to insert an image in a richtextbox control using C#, but so far I'm only failing.

This is the code that I am using:

DataFormats.Format _dataFormat = DataFormats.GetFormat(DataFormats.Bitmap);
Clipboard.SetImage(Image.FromFile(Application.StartupPath + @"\Images\" + i + ".bmp"));
 
chat.Paste(_dataFormat);

The code is not printing any picture but any gives an error sound when executed. I have tried the same code with .bmp images, .jpg images and .png images but keep hitting a dead end.

Can anybody help me with this? Please???

Thanks!



Samuel Fernandes
Samuel Fernandes

Total Post:156

Points:1096
Posted on    September-28-2013 9:07 AM

You can paste below code into your code and call it: place a picture into your project to embeded resource,and call this method passing the richtextbox.

    private void createImage(Control item)
    {   
        Hashtable image = new Hashtable(1);
        image.Add(item,yourproject.Properties.Resources.yourpicturename);
        Clipboard.SetImage((Image)image[item]);
        ((RichTextBox)item).Paste();
    }

Don't want to miss updates? Please click the below button!

Follow MindStick