Reputation: 3
I am currently creating a side project that deals with dual-user communication using DuplexChanneling in C#.
My problem is the implementation of this very simple, yet tedious aspect--emotes.
Here is the code that is giving me trouble:
Hashtable emotions;
void CreateEmotions()
{
emotions = new Hashtable(6);
emotions.Add(":)", ChattingClient.Properties.Resources.regular_smile);
emotions.Add(":(", ChattingClient.Properties.Resources.sad_smile);
}
void AddEmotions()
{
foreach (string emote in emotions.Keys)
{
while (TextBoxDisplay1.Text.Contains(emote))
{
int ind = TextBoxDisplay1.Text.IndexOf(emote);
TextBoxDisplay1.Select(ind, emote.Length);
Clipboard.SetImage((Image)emotions[emote]);
TextBoxDisplay1.Paste();
}
}
}
The error is because
Clipboard.SetImage((Image)emotions[emote]);
It states both:
Error 1 The best overloaded method match for 'System.Windows.Clipboard.SetImage(System.Windows.Media.Imaging.BitmapSource)' has some invalid arguments
and
Error 2 Argument 1: cannot convert from 'System.Windows.Controls.Image' to 'System.Windows.Media.Imaging.BitmapSource' C:\Users\StandardGuy\Desktop\ChattingApplication\ChattingClient\ChattingClient\MainWindow.xaml.cs 68 41 ChattingClient
Upvotes: 0
Views: 993
Reputation: 76
Hashtable emotions;
void CreateEmotions()
{
emotions = new Hashtable(6);
emotions.Add(":)", new BitmapImage(new Uri("/Resources/name_of_picture1.png", UriKind.Relative)));
emotions.Add(":(", new BitmapImage(new Uri("/Resources/name_of_picture2.png", UriKind.Relative)));
}
void AddEmotions()
{
foreach (string emote in emotions.Keys)
{
while (TextBoxDisplay1.Text.Contains(emote))
{
int ind = TextBoxDisplay1.Text.IndexOf(emote);
TextBoxDisplay1.Select(ind, emote.Length);
Clipboard.SetImage((BitmapImage)emotions[emote]);
TextBoxDisplay1.Paste();
}
}
}
Hope this helps!
Upvotes: 1