I need a quick and medium TextBox solution. The RichTextBox is too slow, so I want to go by drawing the owner or creating a user control.
My need is for a text box that can handle large text content and offers simple highlighting by drawing colorful backgrounds around words or individual characters. The important thing is that the text line itself does NOT contain markup for this, and word indices for the mark are stored separately. Indexes relative to the beginning of a text string (also known as the Text property when it comes to .NET TextBox).
I think this will be due to bringing text under my own control, as Windows Edit Control will not be able to do what I need.
My application is Windows Forms. What is the correct way to make such a control, and are there any examples?
Is it possible to do quick control under .NET? (it is already assumed that API calls will be needed). Or is it better done in C ++?
Addendum 1: I think the way to do this is described in response from MarkIsMobile user in question SO Drawing over a TextBox in .NET. Compact Framework . See, OnPaint TextBox is not very useful, as TextBox is a rather complicated control. The approach described in the answer from MarkIsMobile is as follows:
- Replace the standard Windows procedure with your own C # delegate
- But still keep the default behavior and call OldWindowsProc
- Make your own drawing after that.
I have not tried this myself yet, but it would be interesting to see more examples of this.
Moreover. My current approach (the same?) Is to access the control through the NativeWindow class and override WndProc. I just draw over the text with a degree of transparency to create the βcolor markerβ effect that I need, and it actually works great, but not perfect. (Are there ways to draw using raster blending only by coloring the background, not the text in the foreground?)
source share