在C#的textBox或richtextBox中,如何显示图片? 在C#的textBox或richtextBox中,像QQ一样可以显示字同时显示图片该怎么做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以前写的代码: { 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 Runtimehttp://www.codeproject.com/cs/miscctrl/csexrichtextbox.asp 对不起,上面的代码不全;看下面的;//插入到编辑的文本框中,这些图片肯定是本地的公式 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); } } 在www.codeproject.com上,有个叫ExRichTextBox的项目,完成了你要的功能,你可以去下下来看看这个程序还带rtf的编辑格式图片在rtf里好像是以2进制代码的形式存储的。它的存储方式就和你导入一些image到imagelist删除这些image但imagelist还可以显示的道理一样。楼上的那个通过剪贴板来操作也是可以的,但用完后要清剪贴板,而且要赋上剪贴板前面的一个值 ExRichTextBox我用过,可以实现图文混排但是有一点不好,就是字体无法变更 在www.codeproject.com上,有个叫ExRichTextBox的项目,完成了你要的功能,你可以去下下来看看这个程序还带rtf的编辑格式图片在rtf里好像是以2进制代码的形式存储的。它的存储方式就和你导入一些image到imagelist删除这些image但imagelist还可以显示的道理一样。楼上的那个通过剪贴板来操作也是可以的,但用完后要清剪贴板,而且要赋上剪贴板前面的一个值 ArrayList ar1,ArrayList ar2怎么使用?有点看不明白 this.PastImage(textBox);this.TextChanged_Add(textBox.Rtf,ar1,ar2,dname);具体怎么定义的 ? Insert Plain Text and Images into RichTextBox at Runtimehttp://www.codeproject.com/cs/miscctrl/csexrichtextbox.asp textbox中字符串保存为二进制的问题 问个超简单的问题!高手来抢分! 在线等,多线程求助 C# 邮件 <一个传窗体对象的小问题> 求教:java转C#代码 找不到文件或程序集名称“System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToke C#里如何调用C的DLL里有指针类型的函数 关于MailMessage发送邮件 高分的问题:小弟的真心请教 这个正字表达式怎么写? 用钩子碰到的一个问题。
{
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
//插入到编辑的文本框中,这些图片肯定是本地的公式
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);
}
}
这个程序还带rtf的编辑格式
图片在rtf里好像是以2进制代码的形式存储的。
它的存储方式就和你导入一些image到imagelist删除这些image但imagelist还可以显示的道理一样。楼上的那个通过剪贴板来操作也是可以的,但用完后要清剪贴板,而且要赋上剪贴板前面的一个值
但是有一点不好,就是字体无法变更
这个程序还带rtf的编辑格式
图片在rtf里好像是以2进制代码的形式存储的。
它的存储方式就和你导入一些image到imagelist删除这些image但imagelist还可以显示的道理一样。楼上的那个通过剪贴板来操作也是可以的,但用完后要清剪贴板,而且要赋上剪贴板前面的一个值
有点看不明白
this.TextChanged_Add(textBox.Rtf,ar1,ar2,dname);具体怎么定义的 ?
Insert Plain Text and Images into RichTextBox at Runtime
http://www.codeproject.com/cs/miscctrl/csexrichtextbox.asp