Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. RichEditBox, IRichEditOle, IOleObject - Inserting, Saving and Loading embedded Ole objects in a RichTextBox

RichEditBox, IRichEditOle, IOleObject - Inserting, Saving and Loading embedded Ole objects in a RichTextBox

Scheduled Pinned Locked Moved C#
comcsharpgraphicshardware
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anthony Queen
    wrote on last edited by
    #1

    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;

    A 1 Reply Last reply
    0
    • A Anthony Queen

      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;

      A Offline
      A Offline
      Anthony Queen
      wrote on last edited by
      #2

      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.


      E 1 Reply Last reply
      0
      • A Anthony Queen

        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.


        E Offline
        E Offline
        ednrgc
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • E ednrgc

          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

          A Offline
          A Offline
          Anthony Queen
          wrote on last edited by
          #4

          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.


          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups