当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > r在richtextbox中插入动画/控件

ASP.NET
asp.net下用服务器端代码解决浏览器兼容性问题
asp.net 安全的截取指定长度的html或者ubb字符串
asp.net 在线编辑word文档 可保存到服务器
asp.net 提高网站速度及如何利用缓存
asp.net 修改/删除站内目录操作后Session丢失问题
asp.net URL重写简化版 速学URL重写
asp.net EncryptHelper 加密帮助类
asp.net JSONHelper JSON帮助类
C# 调用存储过程简单完整的实例代码
vs2008 安装失败的总结与分享
HttpHandler HttpModule入门篇
ASP.NET(AJAX+JSON)实现对象调用
Asp.net 基于Cookie简易的权限判断
asp.net通过HttpModule自动在Url地址上添加参数
asp.net 字符串、二进制、编码数组转换函数
ASP.NET操作Excel备忘录
记录游客页面访问IP的简易实现代码 (asp.net+txt)
比较简单的将数据信息导入wrod文档方案(C# for word)
增加asp.net应用程序性能的20种方法(简单有效)
ASP.NET 图片防盗链的实现原理分析

ASP.NET 中的 r在richtextbox中插入动画/控件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 53 ::
收藏到网摘: n/a


在richtextbox中插入图片得方法很多,不过一般不能动,要实现动画至少应该实现一个activex控件,不过.net对activex的支持很差,我试过用c#写了个activex,不过效果很差,根本久不能动。
(备注)这里的差不多是从别人的c++代码(蒋晟)和msdn中得来的(所以,我不是个高手)
这是我在gowk中的一部分代码(有删减)拿来共同学习

using System;using System.Drawing;using System.Windows.Forms;using System.Runtime.InteropServices;
using gowk.common;
namespace gowk.controls{ public class GRichTextBox_ :RichTextBox { public GRichTextBox_() { } #region insert ole public void Insersert(IOleObject oleObj) { RichEidtOle ole=new RichEidtOle(this); ole.InsertOle(oleObj); } public void Insersert(Control control) { RichEidtOle ole=new RichEidtOle(this); ole.InsertControl(control); } public void InsertImage(string imageFile) { Image img=Image.FromFile(imageFile); Type t=Type.GetTypeFromProgID("ImageOle.GifAnimator.1"); object o=System.Activator.CreateInstance(t); bool b=o is IOleObject; if(!b)throw(new System.Exception("无法创建Ole对象")); t.InvokeMember("LoadFromFile", System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Instance|System.Reflection.BindingFlags.InvokeMethod, null, o, new object[]{imageFile}); if(b) this.Insersert((IOleObject)o); } class RichEidtOle { private RichTextBox _richEdit; private IRichEditOle _RichEditOle; public RichEidtOle(RichTextBox richEdit) { this._richEdit=richEdit; } private IRichEditOle IRichEditOle { get { if(this._RichEditOle==null) { this._RichEditOle=SendMessage(this._richEdit.Handle,API.EM_GETOLEINTERFACE,0); } return this._RichEditOle; } } public void InsertControl(Control control) { if(control==null)return; IntPtr pLockBytes=API.CreateILockBytesOnHGlobal(IntPtr.Zero,true); IntPtr pStorage=API.StgCreateDocfileOnILockBytes(pLockBytes,STGM.STGM_SHARE_EXCLUSIVE|STGM.STGM_CREATE|STGM.STGM_READWRITE,0); IntPtr pOleClientSite=this.IRichEditOle.GetClientSite(); REOBJECT roeObject=new REOBJECT(); roeObject.clsid=Marshal.GenerateGuidForType(control.GetType()); roeObject.pstg=pStorage; roeObject.poleobj=Marshal.GetIUnknownForObject(control); roeObject.polesite=pOleClientSite; roeObject.dvaspect=DVASPECT.DVASPECT_CONTENT; roeObject.dwFlags=ReoObjectFlag.REO_BELOWBASELINE; this.IRichEditOle.InsertObject(roeObject); control.Select(); control.Focus(); } public void InsertOle(IOleObject oleObject) { if(oleObject==null)return; Guid guid=oleObject.GetUserClassID(); IntPtr pLockBytes=API.CreateILockBytesOnHGlobal(IntPtr.Zero,true); IntPtr pStorage=API.StgCreateDocfileOnILockBytes(pLockBytes,STGM.STGM_SHARE_EXCLUSIVE|STGM.STGM_CREATE|STGM.STGM_READWRITE,0); IntPtr pOleClientSite=this.IRichEditOle.GetClientSite(); REOBJECT roeObject=new REOBJECT(); roeObject.clsid=guid; roeObject.pstg=pStorage; roeObject.poleobj=Marshal.GetIUnknownForObject(oleObject); roeObject.polesite=pOleClientSite; roeObject.dvaspect=DVASPECT.DVASPECT_CONTENT; roeObject.dwFlags=ReoObjectFlag.REO_BELOWBASELINE; this.IRichEditOle.InsertObject(roeObject); } [DllImport("User32.dll", CharSet=CharSet.Auto,PreserveSig=false)] public static extern IRichEditOle SendMessage(IntPtr hWnd, int message, int wParam); } #endregion }}