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. draw rich text in a custom control

draw rich text in a custom control

Scheduled Pinned Locked Moved C#
helpcsharpgraphicsperformance
2 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.
  • D Offline
    D Offline
    Duong Tien Nam
    wrote on last edited by
    #1

    I'm writing a control similar to visio to draw shapes and text, now I want to support rich text drawing into my control. I searched the web and found what they call "windowless rich text control" but it does not have code for C#, below is what I tried to do but it is not work:

    namespace WindowsFormsApplication1
    {
    [Guid("c5bdd8d0-d26e-11ce-a89d-00aa006cadc5")]
    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface ITextHost
    {
    IntPtr TxGetDC();
    IntPtr TxReleaseDC(IntPtr hdc);
    }

    public partial class Form1 : Form, ITextHost
    {
        \[DllImport("riched20.dll")\]
        private static extern int CreateTextServices(
          \[MarshalAs(UnmanagedType.IUnknown)\] object punkOuter,
          ITextHost pITextHost,
          \[MarshalAs(UnmanagedType.IUnknown), Out\] out object ppUnk);
    
        public Form1()
        {
            InitializeComponent();
            this.Load += new EventHandler(Form1\_Load);
        }
    
        void Form1\_Load(object sender, EventArgs e)
        {
            object ppUnk = null;
            int result = CreateTextServices(null, this, out ppUnk);
        }
    
        #region ITextHost Members
    
        public IntPtr TxGetDC()
        {
            return this.Handle;
        }
    
        public IntPtr TxReleaseDC(IntPtr hdc)
        {
            return IntPtr.Zero;
        }
    }
    

    }

    When run into the method CreateTextServices, it keeps saying that the memory is corrupted. I don't know what I did wrong in the code. And I stuck with it. Please help me with that, thanks for your concern.

    J 1 Reply Last reply
    0
    • D Duong Tien Nam

      I'm writing a control similar to visio to draw shapes and text, now I want to support rich text drawing into my control. I searched the web and found what they call "windowless rich text control" but it does not have code for C#, below is what I tried to do but it is not work:

      namespace WindowsFormsApplication1
      {
      [Guid("c5bdd8d0-d26e-11ce-a89d-00aa006cadc5")]
      [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
      public interface ITextHost
      {
      IntPtr TxGetDC();
      IntPtr TxReleaseDC(IntPtr hdc);
      }

      public partial class Form1 : Form, ITextHost
      {
          \[DllImport("riched20.dll")\]
          private static extern int CreateTextServices(
            \[MarshalAs(UnmanagedType.IUnknown)\] object punkOuter,
            ITextHost pITextHost,
            \[MarshalAs(UnmanagedType.IUnknown), Out\] out object ppUnk);
      
          public Form1()
          {
              InitializeComponent();
              this.Load += new EventHandler(Form1\_Load);
          }
      
          void Form1\_Load(object sender, EventArgs e)
          {
              object ppUnk = null;
              int result = CreateTextServices(null, this, out ppUnk);
          }
      
          #region ITextHost Members
      
          public IntPtr TxGetDC()
          {
              return this.Handle;
          }
      
          public IntPtr TxReleaseDC(IntPtr hdc)
          {
              return IntPtr.Zero;
          }
      }
      

      }

      When run into the method CreateTextServices, it keeps saying that the memory is corrupted. I don't know what I did wrong in the code. And I stuck with it. Please help me with that, thanks for your concern.

      J Offline
      J Offline
      Jimmanuel
      wrote on last edited by
      #2

      Have you seen the Graphics[^] class? If you handle the OnPaint event of a control you can use it to draw anything you want on it. :badger:

      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