TextBox custom borders and background

fredriko

Active member
Joined
Jun 3, 2004
Messages
35
Programming Experience
10+
I have come across a need to modify the textbox control (i.e. add colored borders and a gradient background). I have a seen a couple of example on how to modify the border color which consist of creating a new usercontrol, adding a textbox and manually drawing a border.
I would prefer however to inherit from the textbox control and simply override the drawing functions. Does anybody know how I could achieve this? I have tried overriding OnPaint and OnPaintBackground but nothing seems to happen?
 
You probably arent getting any results from this because you didnt add this line in the constructor of your derived TextBox class:

VB.NET:
Public Sub New()
	MyBase.New()
		
	Me.SetStyle(ControlStyles.UserPaint, True)
End Sub

The problem you have with adding a border is that the ClipRectangle for the textbox is only the TextBox's size - not larger where you would be drawing the border.

I've overriden TextBoxes loads of times to format text - but never to do the kind of painting you want to do. It might be possible.. Im not sure! :D

mafro
 
Back
Top