RichEditBox, IRichEditOle, IOleObject - Inserting, Saving and Loading embedded Ole objects in a RichTextBox
-
This is a very complex question, so please bare with me. I'm using VB.net and C# (both vs2003), on a Windows XP machine. First off, I have some code that allows me to retrieve an IRichEditOle object from a rich text box. With this object, I can insert an object into a RichTextBox control. After inserting the object(s), I can then call GetObjectCount and GetObject to iterate through the Ole objects embedded within the RichTextBox. The code for retrieving the RichEditOle interface and for inserting and retrieving objects (the meat of the application) is written in C#. I have also written a custom control that inherits from "System.Windows.Forms.Label" and also implements IOleObject. This code is in VB.NET. It is registered for COM Interop and the appropriat guids have been generated. Besides the basic Label functionality, it also eposes extra public properties (strings). The idea is that a user would be able to insert this custom label control anywhere within a RichTextBox. It works. I can insert and remove multiple controls. I can iterate through the collection of controls in the RichTextBox, cast them back to the custom label, and access each of their properties. It seems to be working perfect. However, when I save the RTF, and then try to reload, I completely lose the embedded information. Everything else is there, just no custom labels in the RichTextBox. I can open the RTF in Notepad and see that there is embedded information. It saved, but didn't load. I'm thinking that at least part of my problem might be that I'm not implementing the correct interfaces to allow the custom label to persist itself within the RTB. It might also be that I'm not inserting the object correctly within the RTB. The insertion part is fairly straightforward though. I have a REOBJECT class that I populate and pass to the IRichEditOle::InsertObject(REOBJECT re) method Here's some of the code: using System; using System.ComponentModel; using System.Collections; using System.Diagnostics; using System.Drawing; using System.Runtime.InteropServices; using Microsoft.VisualStudio.OLE.Interop; [StructLayout(LayoutKind.Sequential)] 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;
-
This is a very complex question, so please bare with me. I'm using VB.net and C# (both vs2003), on a Windows XP machine. First off, I have some code that allows me to retrieve an IRichEditOle object from a rich text box. With this object, I can insert an object into a RichTextBox control. After inserting the object(s), I can then call GetObjectCount and GetObject to iterate through the Ole objects embedded within the RichTextBox. The code for retrieving the RichEditOle interface and for inserting and retrieving objects (the meat of the application) is written in C#. I have also written a custom control that inherits from "System.Windows.Forms.Label" and also implements IOleObject. This code is in VB.NET. It is registered for COM Interop and the appropriat guids have been generated. Besides the basic Label functionality, it also eposes extra public properties (strings). The idea is that a user would be able to insert this custom label control anywhere within a RichTextBox. It works. I can insert and remove multiple controls. I can iterate through the collection of controls in the RichTextBox, cast them back to the custom label, and access each of their properties. It seems to be working perfect. However, when I save the RTF, and then try to reload, I completely lose the embedded information. Everything else is there, just no custom labels in the RichTextBox. I can open the RTF in Notepad and see that there is embedded information. It saved, but didn't load. I'm thinking that at least part of my problem might be that I'm not implementing the correct interfaces to allow the custom label to persist itself within the RTB. It might also be that I'm not inserting the object correctly within the RTB. The insertion part is fairly straightforward though. I have a REOBJECT class that I populate and pass to the IRichEditOle::InsertObject(REOBJECT re) method Here's some of the code: using System; using System.ComponentModel; using System.Collections; using System.Diagnostics; using System.Drawing; using System.Runtime.InteropServices; using Microsoft.VisualStudio.OLE.Interop; [StructLayout(LayoutKind.Sequential)] 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;
Looks like I've stumped the experts. ;-)
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.
-
Looks like I've stumped the experts. ;-)
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.
I'm not sure if this will help, but this project seems to work with embedded objects: http://www.codeproject.com/cs/miscctrl/richtextboxplus.asp
-
I'm not sure if this will help, but this project seems to work with embedded objects: http://www.codeproject.com/cs/miscctrl/richtextboxplus.asp
Thanks for the article, however, it isn't really what I'm looking for. It does show a media player control within the RTB and how to access it, but that's not what I need. I have a custom control written in vb.net that I can already insert into a RTB. It seems like I save it ok, but when I reload the document, the controls are gone. The data in the RTF is stripped out during the load method of the RTB. I need to be able to save the RTF with the embedded controls (and maintain their state), then reload the RTF later with all of the controls intact. My best guess now is that my custom control isn't implementing the correct interfaces, or isn't getting registered correctly. Any help is appreciated.
It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.