在网上找到了个可以贴gif图进去的,但是无法读取出来,有的又不会动, 想找个实用的。。
不关要能显示gif,而且还需要能读取的出来复制到其他的richtextbox里。
不关要能显示gif,而且还需要能读取的出来复制到其他的richtextbox里。
解决方案 »
- 在Treeview中现在文本文档目录(急!!)
- 编写一个程序,使得程序每次都能显示上一次运行的时间?本人菜鸟,请大家解答!谢谢
- 页面post 怎么做???
- dephi调用.net的dll
- arraylist动态数组问题~
- 提高速度的问题
- 关于刷B189带QQ版的问题
- 关于链接数据库的一个问题?
- windows 服务下SerialPort的DataReceived事件一直不触发
- 如果微软继续跟进Java,他们迟早会把它消灭掉,而Java其实不过是Windows和Internet之战的牺牲品!!!
- 求教:关于 listView 绑定 及 方法调用问题
- dev的gridview,某一个列,根据条件,在字段前面加不同图标。
winform的WebBrowser可以用来做聊天编辑器的吗? 这个我就不晓得了哦~。
winform的WebBrowser可以用来做聊天编辑器的吗? 这个我就不晓得了哦~。
不能,具体 这个我也不晓得了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.ComponentModel;namespace ControlLib
{
public class RichTextBoxEx : RichTextBox
{
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int message, IntPtr wParam, IntPtr lParam);
[DllImport("User32.dll", CharSet = CharSet.Auto, PreserveSig = false)]
internal static extern IRichEditOle SendMessage(IntPtr hWnd, int message, int wParam); [StructLayout(LayoutKind.Sequential)]
private struct CHARFORMAT2_STRUCT
{
public UInt32 cbSize;
public UInt32 dwMask;
public UInt32 dwEffects;
public Int32 yHeight;
public Int32 yOffset;
public Int32 crTextColor;
public byte bCharSet;
public byte bPitchAndFamily;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public char[] szFaceName;
public UInt16 wWeight;
public UInt16 sSpacing;
public int crBackColor;
public int lcid;
public int dwReserved;
public Int16 sStyle;
public Int16 wKerning;
public byte bUnderlineType;
public byte bAnimation;
public byte bRevAuthor;
public byte bReserved1;
} private const int WM_USER = 0x0400;
private const int EM_GETCHARFORMAT = WM_USER + 58;
private const int EM_SETCHARFORMAT = WM_USER + 68;
private const int SCF_SELECTION = 0x0001;
private const UInt32 CFE_LINK = 0x0020;
private const UInt32 CFM_LINK = 0x00000020;
IRichEditOle _richEditOle = null;
IRichEditOle richEditOle
{
get
{
if (this._richEditOle == null)
{
IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr)));
IntPtr richEditOleIntPtr = IntPtr.Zero;
Marshal.WriteIntPtr(ptr, IntPtr.Zero);
try
{
int msgResult = SendMessage(this.Handle, RichEditOle.EM_GETOLEINTERFACE, IntPtr.Zero, ptr);
if (msgResult != 0)
{
IntPtr intPtr = Marshal.ReadIntPtr(ptr);
try
{
if (intPtr != IntPtr.Zero)
{
Guid guid = new Guid("00020D00-0000-0000-c000-000000000046");
Marshal.QueryInterface(intPtr, ref guid, out richEditOleIntPtr); this._richEditOle = (IRichEditOle)Marshal.GetTypedObjectForIUnknown(richEditOleIntPtr, typeof(IRichEditOle));
}
}
finally
{
Marshal.Release(intPtr);
}
}
}
catch (Exception err)
{
Trace.WriteLine(err.ToString());
}
finally
{
Marshal.FreeCoTaskMem(ptr);
}
}
return this._richEditOle;
}
} class RichEditOle
{
[DllImport("ole32.dll", PreserveSig = false)]
static extern int CreateILockBytesOnHGlobal(IntPtr hGlobal, bool fDeleteOnRelease, [Out] out ILockBytes ppLkbyt);
[DllImport("ole32.dll")]
static extern int StgCreateDocfileOnILockBytes(ILockBytes plkbyt, uint grfMode, uint reserved, out IStorage ppstgOpen); public const int EM_GETOLEINTERFACE = 0x0400 + 60; private RichTextBoxEx richTextBox;
private IRichEditOle ole; internal RichEditOle(RichTextBoxEx richEdit)
{
this.richTextBox = richEdit;
this.ole = SendMessage(this.richTextBox.Handle, EM_GETOLEINTERFACE, 0);
} internal void InsertControl(Control ctrl)
{
if (ctrl == null)
return; Guid guid = Marshal.GenerateGuidForType(ctrl.GetType()); ILockBytes lockBytes;
CreateILockBytesOnHGlobal(IntPtr.Zero, true, out lockBytes); IStorage storage;
StgCreateDocfileOnILockBytes(lockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE | STGM.STGM_READWRITE), 0, out storage); IOleClientSite oleClientSite;
this.ole.GetClientSite(out oleClientSite); REOBJECT reObject = new REOBJECT()
{
cp = this.richTextBox.SelectionStart,
clsid = guid,
pstg = storage,
poleobj = Marshal.GetIUnknownForObject(ctrl),
polesite = oleClientSite,
dvAspect = (uint)(DVASPECT.DVASPECT_CONTENT),
dwFlags = (uint)0x00000002,
}; try
{
reObject.dwUser = 1;
}
catch { } this.ole.InsertObject(reObject); Marshal.ReleaseComObject(lockBytes);
Marshal.ReleaseComObject(oleClientSite);
Marshal.ReleaseComObject(storage);
}
}
public RichTextBoxEx()
: base()
{
base.BorderStyle = BorderStyle.FixedSingle;
this.DetectUrls = false;
} public new bool ReadOnly { get; set; } protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x0100:
if (this.ReadOnly)
return;
break;
case 0X0102:
if (this.ReadOnly)
return;
break;
default:
break;
}
base.WndProc(ref m);
} List<MyGIF> gifList = new List<MyGIF>();
Panel gifPanel = new Panel(); [DefaultValue(false)]
public new bool DetectUrls
{
get { return base.DetectUrls; }
set { base.DetectUrls = value; }
} public void InsertGIF(string Name, Image Data)
{
//MyGIF gif = new MyGIF(Name, Data);
//gif.Box.Invalidate();
//this.gifPanel.Controls.Add(gif.Box);
//this.gifList.Add(gif); //RichEditOle ole = new RichEditOle(this);
//ole.InsertControl(gif); //this.Invalidate();
} public void InsertControl(Control ctrl)
{
this.gifPanel.Controls.Add(ctrl);
RichEditOle ole = new RichEditOle(this);
ole.InsertControl(ctrl); this.Invalidate();
} public string GetGIFInfo()
{
string imageInfo = "";
REOBJECT reObject = new REOBJECT();
for (int i = 0; i < this.richEditOle.GetObjectCount(); i++)
{
this.richEditOle.GetObject(i, reObject, GETOBJECTOPTIONS.REO_GETOBJ_ALL_INTERFACES);
MyGIF gif = this.gifList.Find(p => p != null && p.Index == reObject.dwUser);
if (gif != null)
{
imageInfo += reObject.cp.ToString() + ":" + gif.Name + "|";
}
}
return imageInfo;
} }
}
GetGIFInfo(), 用于返回RichTextBox中所有的ole对象。更详细的请参考:
1.将播放器插入到RichTextBox: http://www.codeproject.com/Articles/4528/Use-IRichEditOle-from-C
2.(推荐):http://www.csharpwin.com/csharpresource/2667.shtml
他所介绍的3种方法,均基于Ole, ole控件的实现方法一个来源于腾讯,一个来源于飞信,第三个是作者自己实现的类,前两个我测试失败,第三种方法推荐参考 。
可以插入任何controlhttp://www.codeproject.com/Articles/134358/TRichTextBox-A-universal-RichTextBox-which-can-dis
为public 就可以获取当前richtextbox中所有已插入的控件
找到对应的picturebox 复制其中的image 粘贴的时候 再用image生成一个picturebox插入到另外一个richtextbox中
如果是VS自带的WebBrowser控件,有一个MODE的标识的,只要设置为EditMode就是编辑模式了!更简单的方法是:
在html的body里添加contenteditable="true"属性如<html><head><title>example</title></head><body contenteditable="true"> 这里是可以编辑的</body> </html>
这是效果,需要选择第三种方式:GifBox
你的电脑太神奇了, 连接仍然是有效的
我本地也有源码, 需要的话留个你的邮箱。
好了,我下载到源码了,可是如何复制出来呢? 发送的时候获取不到图片也没用吖。可以肯定的是绝对能够获取到图片,
但,这需要仔细看看 8楼代码中的 GetGIFInfo()方法,
首先通过 richEditOle.GetObjectCount()获得RichtextBox中Ole控件的数量,再循环执行
richEditOle.GetObject()挨个获取详细的Ole控件信息,
他的返回值是一个结构:public class REOBJECT
{
public int cbStruct = Marshal.SizeOf(typeof(REOBJECT)); // Size of structure
public int cp; // Character position of object
public Guid clsid; // Class ID of object
public IntPtr poleobj; // OLE object interface
public IStorage pstg; // Associated storage interface
public IOleClientSite polesite; // Associated client site interface
public Size sizel; // Size of object (may be 0,0)
public uint dvAspect; // Display aspect to use
public uint dwFlags; // Object status flags
public uint dwUser; // Dword for user's use
}
包含了丰富的信息,其中CP属性描述当前Ole位于RichtextBox中的位置(他是动态的,会因为实际位置改变而自动变化 ),
poleobj 属性则是一个指针,指向你的图片控件, 是你InsertControl()时插入的控件, 如果插入的是GifBox,可以使用以下代码转换:
GifBox ibx = Marshal.GetObjectForIUnknown(REOBJECT.poleobj) as GifBox;获取到了图片位置,以及图片,剩下的就是如何将他们告诉给接收者了。