title: Owner draw TextBox for use in WinForms
body: <p>I need a lean &amp; mean TextBox solution. A RichTextBox proves too slow, so I want to go the way of owner drawing, or custom control building.</p>
  
  <p>My need is for a textbox that can handle large text content and offers simple highlighting by drawing colored backgrounds around words or single characters. Important is, that the text string itself does NOT contain markup for this, but rather, the indices of words to mark are stored separately. Indices relative to the start of the text string (also known as the Text property when talking about a .NET TextBox).</p>
  
  <p>I think it will have to involve drawing the text under my own control as the Windows Edit Control will not be able to do what I need.</p>
  
  <p>My application is Windows Forms. What is the proper way to make a control like this, and are there any examples?</p>
  
  <p>And can one make a fast control under .NET? (already assuming native API calls will be needed). Or is this better done in C++?</p>
  
  <hr>
  
  <p><strong>Addition 1:</strong> I think the way to do this is as described by the answer from user MarkIsMobile in the SO question <a href="https://stackoverflow.com/questions/524784/">Drawing over a TextBox in .NET Compact Framework</a>. See, the OnPaint of the TextBox is not really useful, as the TextBox is a rather quirky control. The approach as outlined in the answer from MarkIsMobile is as follows:</p>
  
  <ul>
  <li>Replace the default Windows Procedure with your own C# delegate</li>
  <li>But still keep the 'default' behavior, and call 'OldWindowsProc'</li>
  <li>Do your own custom drawing after this</li>
  </ul>
  
  <p>I haven't been trying this myself <em>yet</em>, but would be interested to see more examples of this.</p>
  
  <p>Also. My current approach is (the same?) to get access to the control via the NativeWindow class and override WndProc. I simply draw <strong>over</strong> the text with a degree of transparency to create the 'color marker' effect that I'm after, and this works fine actually - but is not perfect. (<em>Are</em> there ways to draw with bitmap blending, only colorizing the background and not the text in the foreground?)</p>