i have to retrieve data in my richtxtbox from my database ... how can i convert the retieved format of image source into a smily in windows form .. help please

fenrir i need to retrieve smilies from my database itself ,,, jux guide me converting this image source to a smilie in my rich text box ... please ...

Are you saving the physical image? or just the path.. Try this Click Here you will still need to first link to get your image into the Richedit.

Edited 2 Years Ago by Fenrir()

i have ol the images in my resources
,, is it necessary i have to add them to my database , as i dont wish to alter my database by some due reasons ...... cant i use my resources to display a smiley corresponging to <img src="images/smiley-yell.png"> such column entry ... in my table

fenrir in the video ... they added picture to picturebox the same way when i did i cudn't add it to my richtext box .... please prescribe some other alternative

Once you have the image from the database the first step is done. Richtextbox doesn't have default methods for adding images so that's why i suggested that first article. Have you gone through it?

yes fenrir i studied it ... added emoticons to my resources ... as well ,, but itz getting vrry typical for me to find out wat i actualyy need .. as i simply want to match d emoticon with the php image source i have in my database ..

Okay so you have the string from the database so next you need to find the image in the resources. Did you manually add them to resources? are they inside an image list? At runtime just create a List<string> containing all your resource images. And match them by checking If (List.Contains("Image"))if it finds a match then you can can add the image from the resource.

foreach (string image in System.IO.Directory.GetFiles(@"Resources\"))
{
  MyList.Items.Add(image);
}

This is to get the initial list of your resources. Again i'm not sure how you you added the images to your project.

 void chatting()
        {

           // MessageBox.Show(videoid);
            string myconnection = "connection string";
              MySqlConnection myConn = new MySqlConnection(myconnection);

              MySqlCommand SelectCommand = new MySqlCommand("select * from livestream.users INNER JOIN livestream.chat INNER JOIN livestream.video  ON users.user_id = chat.user_id and chat.channel_id=video.video_id where chat.channel_id ='" + videoid + "' and isACTIVE=1 order by chat.chatID DESC", myConn);
              MySqlDataReader myReader;


              try
              {
                  myConn.Open();
                  myReader = SelectCommand.ExecuteReader();
                  List<string> list = new List<string>();
                  Graphics g = Graphics.FromHwnd(this.Handle);
                  ImageList photoList = new ImageList();
                  photoList.Images.Add(Image.FromFile(@"img. path"));
                  photoList.Images.Add(Image.FromFile(@"img1 path"));
                  photoList.Images.Add(Image.FromFile(@"img 2 path "));

                  while (myReader.Read())
                  {
                      string test1 = myReader.GetString("user_name");
                      string test = myReader.GetString("message");
                      test = test.Substring(test.IndexOf(";") + 1);
                      list.Add(test1 + "   " + test);
                      if (test.Contains("Image"))
                      {
                          foreach (string image in System.IO.Directory.GetFiles(@"Resources\"))
                          {
                              list.Items.Add(image);
                          }
                      }
                  }
                  chattingbox.Lines = list.ToArray();

              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);
              }
              myConn.Close();


        }

m getting an error .. donno y ? i evn declared the photolist , i sent u a snapshot ...... can u c and help ..... actually m making a chat box so , the conditional logic should be that if i have msg the test condition executes else the image from resources ....

Edited 2 Years Ago by Amanpreet_1

Attachments png.png 189.54 KB

theres no error but i suppose itz nt gng in the if loop when getting an image source in message column

Attachments clips.png 298.34 KB
    Hashtable emotions;
        void createEmotions()
        {
            emotions = new Hashtable(3);
            emotions.Add(":-)", WindowsFormsApplication1.Properties.Resources.smiley_yell);
            emotions.Add(":-(", WindowsFormsApplication1.Properties.Resources.smiley_upset);
            emotions.Add(":-*", WindowsFormsApplication1.Properties.Resources.smiley_kiss);
        }
        void AddEmotions()
        {
            foreach (string emote in emotions.Keys)
            {
                while (chattingbox.Text.Contains(emote))
                {
                    int ind = chattingbox.Text.IndexOf(emote);
                    chattingbox.Select(ind, emote.Length);
                    Clipboard.SetImage((Image)emotions[emote]);
                    chattingbox.Paste();
                }
            }
        }

this code is helpin me get smilies bt only when i manuaalyy write the string :-) or such in richtextbox but thats nt my purpose ..
If (List.Contains("Image")) .. u told to put this condition .. ryt ? but my list contains itz image source not the image as i told earlier thats whr the problm stands .... my message column contains its source and not image so i need some condition ... that only pick smiley-yell.png from the source and returns the corresponding pic from resources

Edited 2 Years Ago by Amanpreet_1

This article has been dead for over six months. Start a new discussion instead.