Click here to Skip to main content
16,016,580 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello....

I an working on wpf richtextbox control i want to inster image in each paragraph
and insert (Text+Image) into sql table.


i have problem while i try to paste image on richtextbox some time it work some time doesn't show anything...

C#
OpenFileDialog dlg = new OpenFileDialog();
                dlg.Title = "Add image";
                dlg.Filter = "png,jpg|*.png;*.jpg";
                if (dlg.ShowDialog() == true)
                {
                    System.Threading.Thread.Sleep(20);
                    var clipboard = Clipboard.GetDataObject();
                    BitmapImage bitmapImage = SetImage(dlg.FileName);
                    Clipboard.SetImage(bitmapImage);
                    txt.Paste();
                    Clipboard.SetDataObject(clipboard);
                }


private BitmapImage SetImage(String filename)
        {
            BitmapImage bi = new BitmapImage();
            if (System.IO.File.Exists(filename))
            {
                bi.BeginInit();
                bi.CacheOption = BitmapCacheOption.OnLoad;
                bi.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                bi.UriSource = new Uri(filename);
                bi.EndInit();
            }
            return bi;
        }


pls help..... let me know why this is not working where i am wrong.....
with this code...

[Edit]Code block added[/Edit]
Posted
Updated 26-Oct-12 22:29pm
v2

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