Sign in to follow this  
BlackGhost

[.net] Drawing custom graphics on existing controls

Recommended Posts

I'm trying to do some kind of code editor by overriding the RichTextBox class, so I want to highlight a line of code. The obvious way to do that seemed to be to override the OnPaint stuff and draw a rectangle there, with a height equal to the line's height. However, that doesn't seem to work, and any drawing code does not seem to actually draw anything, maybe getting overwritten by the RichTextbox's visuals even though I'm never calling the base class' onPaint. Is there is a way to actually draw on the controll I'm inheriting from? Thanks for any input.

Share this post


Link to post
Share on other sites
RichTextBox has always been hard to modify for a whole bunch of reasons. You might want to try subclassing it and overriding the WndProc function. Look for WM_PAINT events, pass them to the base class then do your own drawing on top. Might work. It would mean you'd have to use GDI calls on an HDC unless there's some way to initialize a Graphics object from one.

But you could probably acheive the same effect justing the RichTextBox's native features - it'll allow you to assign different fonts to different ranges of text in the box. So make a Red font or a Green font and apply those.

I mean, I assume you are trying to do this in a chroma-coding sort of manner.

Share this post


Link to post
Share on other sites
Thanks, I will probably try that. And yes, there are Graphics.FromHDC and Graphics.FromHwnd functions that create the managed graphics object from native handles. I know about the richtextbox being able to change text colors and fonts, but i need more than that (e.g. highlight the whole background of the line, not just its text).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this