How to apply a gradient to a textbox?

D

Don

I'm making a custom control that has a multiline textbox on it. I want to
make the textbox have a gradient background. On my custom control's Paint
event I call a routine that draws a gradient on the textbox's background,
but the gradient starts appearing at the bottom of the textbox after the
last line of text. It's almost as if VB draws the gradient on the entire
textbox, then blanks out the part of the textbox that actually displays text
with a solid color background, leaving the gradient on the rest of the
textbox after the last line of text.

I use the following code to create this "half-finished" gradient effect:


Graphics.FromHwnd(TextBox.Handle).FillRectangle( _
New Drawing2D.LinearGradientBrush( _
TextBox.ClientRectangle, _
Color1, _
Color2, _
Drawing2D.LinearGradientMode.Horizontal), _
TextBox.ClientRectangle)


Maybe I shouldn't be using the ClientRectangle property of the textbox? Is
it even possible to do what I want to do (which basically amounts to a text
on a non-solid background)?

And, no, I can't use a label, unless you can put scrollbars on a label.

- Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top