C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 307,184 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,606 people online right now. Registration is fast and FREE... Join Now!




Inserting Image into Rich TextBox - Error on typeof (resouce error)

 

Inserting Image into Rich TextBox - Error on typeof (resouce error)

Tertitten

4 Mar, 2009 - 06:17 AM
Post #1

New D.I.C Head
*

Joined: 2 Mar, 2009
Posts: 9

I'm trying as best as I can to add a image into a Rich TextBox (ExRich TextBox)

This code
CODE

                rtfChat.InsertImage(new Bitmap(typeof(ResourceManager), "Heart.png"));

Is what's giving me a real headache. Whenever I try to insert the image I get Error: "Can't Find the resource Heart.png In the Class System.Resources.ResourceManager" (roughly translated)

I have tried various typeof classes, but honestly I don't know which one to "select"
I'm stucked to say the least

The entire code is:
CODE

        private void rtfChat_TextChanged(object sender, EventArgs e)
        {
            try
            {
                int _index;
                if ((_index = rtfChat.Find(":)")) > -1) {
                    rtfChat.Select(_index, ":)".Length);
                rtfChat.InsertImage(new Bitmap(typeof(ResourceManager), "Heart.png"));
                }
            }

What I'm actually trying to achieve is that whenever ":)" is active in the Rich Text the text ":)" should be replaced by a Image (not entire text, but only ":)" )

I've spent hours on this so I would really appreciate some help.

User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 1)

PsychoCoder

RE: Inserting Image Into Rich TextBox - Error On Typeof (resouce Error)

4 Mar, 2009 - 10:50 AM
Post #2

I Code, Therefore I am
Group Icon

Joined: 26 Jul, 2007
Posts: 14,940



Thanked: 519 times
Dream Kudos: 11575
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Well this is the easiest way I know of for getting an image from a Resource file

CODE

ResourceManager manager = new ResourceManager ("myResources", Assembly.GetExecutingAssembly());
Bitmap bmp = new (Bitmap)manager.GetObject("myImage");
rtfChat.InsertImage((Image)bmp);


Just so you know what to change, here's how I created my resource file and added an image to it

CODE

private void CreateResourceFile()
{
    System.Resources.ResourceWriter writer = new System.Resources.ResourceWriter("myResources.resources");

    writer.AddResource("myImage", new Bitmap("test.jpg"));
    writer.Generate();
}


So then your method would look like this

CODE

private void rtfChat_TextChanged(object sender, EventArgs e)
{
    try
    {
        int _index;
        if ((_index = rtfChat.Find(":)")) > -1)
        {
            rtfChat.Select(_index, ":)".Length);
           Bitmap bmp = new (Bitmap)manager.GetObject("myImage");
           rtfChat.InsertImage((Image)bmp);
        }
    }
    catch (Exception ex)
    {
        //do your error catching here
    }
}


Hope that helps smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:51PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month