Link to home
Start Free TrialLog in
Avatar of derekthornton
derekthornton

asked on

RichTextBox Border Color

How can I change the color of a RichTextBox's Border? I've tried overriding paint, but this causes a lot of problems when the TextBox is displayed inside of other controls ...
Avatar of ptmcomp
ptmcomp
Flag of Switzerland image

Usually the border is painted by the Message handler of WM_NCPAINT. They are not avaible as methods in the .net Framework. But you can override the WndProc to handle it. You will need to mess a bit around with the Win32 API (GDI).
Avatar of derekthornton
derekthornton

ASKER

Okay ..That doesn't do me much good, I know nothing of the Win32 API ...
ASKER CERTIFIED SOLUTION
Avatar of Razzie_
Razzie_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hrnm.. That's almost what I'm lookign for ..is there any way to eliminate the 3D-esque look to the border? Setting it to "FixedSingle" sure doesn't do that...
Hmmm I noticed. Strange. I don't know that - I'll get back to you about that.
Alright. Thanks. I'll keep trying tinkering with it in the meantime. If you can't figure it out, tell me and I'll go ahead and give the points to you. But I'd like to get rid of the 3D Border thing if it's possible.
I got this from the MSDN:

'The derived class, RichTextBox, does not support the BorderStyle.FixedSingle style. This style will cause the borderstyle to use the BorderStyle.Fixed3D style instead.' (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformstextboxbaseclassborderstyletopic.asp)


However, you might try the following. In the WndProc method, instead of:

Rectangle r = new Rectangle(0,0,this.Size.Width,this.Size.Height);

use:

Rectangle r = new Rectangle(1,1,this.Size.Width-2,this.Size.Height-2);
------------------------------

This is very dirty code of course, but at least the border looks solid now :)







Yeah ..but it still looks tacky. Now the border is all thick and ugly, I was hoping to get a 1pt size border. I guess it's not possible with a RichTextBox control....
Why is the 'OnPaint" method in that example, btw? It's never called.
Hmm well if you change the Pen size to 1 ( Pen p = new Pen(b,1); ) it doesn't look awesome, but still decent imho (especially with darker colors)

Well if I'll ever stumble across a good solution sometime I'll let you know, thanks and take care.
I think you have to implement a message handler for the WM_NCCALCSIZE message. But I don't know if it will work.
Where are you supposed to get the constant values for the 'messages' that WndProc passes? Seriously. Do you just make them up or something?
You can leave the OnPaint method - forgot to get rid of it, just like the struct.
You can find constant values in the windows.h header file (found in the SDK) and I'm sure there are some internetsites listing them.