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

ASP.NET
FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用方法
.NET 常用功能和代码小结
在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程序意外退出
asp.net IList查询数据后格式化数据再绑定控件
asp.net sql存储过程
asp.net 简单实现禁用或启用页面中的某一类型的控件
asp.net(c#)获取内容第一张图片地址的函数
The remote procedure call failed and did not execute的解决办法
ASP.NET 在线文件管理
asp.net 读取并修改config文件实现代码
ASP.NET Cookie 操作实现
asp.net Silverlight中的模式窗体
Silverlight中动态获取Web Service地址
asp.net Silverlight应用程序中获取载体aspx页面参数
asp.net 水晶报表隔行换色实现方法
asp.net 获取Gridview隐藏列的值
手动把asp.net的类生成dll文件的方法
asp.net 使用ObjectDataSource控件在ASP.NET中实现Ajax真分页
动态指定任意类型的ObjectDataSource对象的查询参数
asp.net Md5的用法小结

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 59 ::
收藏到网摘: 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 }}