在C#的textBox或richtextBox中,像QQ一样可以显示字同时显示图片该怎么做?

解决方案 »

  1.   

    以前写的代码:
    {
    textBox.Paste(DataFormats.GetFormat(DataFormats.Bitmap));
    } public void ClipImage(string name)
    {
    if(File.Exists(imgFilePath+name))
    {
    Image img=Image.FromFile(imgFilePath+name);
    Clipboard.SetDataObject(img);
    }
    else
    {
    Clipboard.SetDataObject( this.DownloadImage( name ) );
    }
    } //插入图片到预览的文本框中,图片可能是本地和服务器上的
    public void InsertImage(RichTextBox textBox,string name)
    {
    if(!File.Exists(imgFilePath+name))
    {
        this.DownloadImage(name);
    }
        this.ClipImage(name); this.PastImage(textBox);
    }还可以参考这个:
    Insert Plain Text and Images into RichTextBox at Runtime
    http://www.codeproject.com/cs/miscctrl/csexrichtextbox.asp
      

  2.   

    对不起,上面的代码不全;看下面的;
    //插入到编辑的文本框中,这些图片肯定是本地的公式
    public void InsertImage( RichTextBox textBox,ArrayList ar1,ArrayList ar2 )
    {
    OpenFileDialog openFileDialog1=new OpenFileDialog();
    openFileDialog1.Filter="所有图象文件(*.*)|*.*"; string dname="";
    if(openFileDialog1.ShowDialog() == DialogResult.OK)
    {
    string fullName=openFileDialog1.FileName;

    string prefix=fullName.Substring(fullName.LastIndexOf(".")+1);
    string name=fullName.Substring(fullName.LastIndexOf(@"\")+1);
    //
    // 把图片放在本地的文件夹中
    //
    dname=MainFile.TheTeacher.Name+"_"+DateTime.Now.Year.ToString()+"_"+DateTime.Now.Month.ToString()+"_"+DateTime.Now.Day.ToString()+"_"+DateTime.Now.Hour.ToString()+"_"+DateTime.Now.Second.ToString()+"_"+DateTime.Now.Millisecond.ToString()+"."+prefix;
    string fullDName=imgFilePath+dname;

    File.Move(fullName,fullDName);

    Image img=Image.FromFile(fullDName); Clipboard.SetDataObject(img);
    this.PastImage(textBox);
    //
    // add the pic
    //
    this.TextChanged_Add(textBox.Rtf,ar1,ar2,dname);
    }
    }
      

  3.   

    在www.codeproject.com上,有个叫ExRichTextBox的项目,完成了你要的功能,你可以去下下来看看
    这个程序还带rtf的编辑格式
    图片在rtf里好像是以2进制代码的形式存储的。
    它的存储方式就和你导入一些image到imagelist删除这些image但imagelist还可以显示的道理一样。楼上的那个通过剪贴板来操作也是可以的,但用完后要清剪贴板,而且要赋上剪贴板前面的一个值
      

  4.   

    ExRichTextBox我用过,可以实现图文混排
    但是有一点不好,就是字体无法变更
      

  5.   

    在www.codeproject.com上,有个叫ExRichTextBox的项目,完成了你要的功能,你可以去下下来看看
    这个程序还带rtf的编辑格式
    图片在rtf里好像是以2进制代码的形式存储的。
    它的存储方式就和你导入一些image到imagelist删除这些image但imagelist还可以显示的道理一样。楼上的那个通过剪贴板来操作也是可以的,但用完后要清剪贴板,而且要赋上剪贴板前面的一个值
      

  6.   

    ArrayList ar1,ArrayList ar2怎么使用?
    有点看不明白 
      

  7.   

    this.PastImage(textBox);
    this.TextChanged_Add(textBox.Rtf,ar1,ar2,dname);具体怎么定义的 ?
      

  8.   


    Insert Plain Text and Images into RichTextBox at Runtime
    http://www.codeproject.com/cs/miscctrl/csexrichtextbox.asp