[vb.net]

G

Guest

well i'm trying to create a control that inherits from textbox or richtextbox
to make the background gradient

i use the following code :

CODE
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
Dim gbr As LinearGradientBrush = New LinearGradientBrush(New Rectangle(0, 0,
Me.Width, Me.Height), Color.White, Color.Blue, LinearGradientMode.Horizontal)
e.Graphics.FillRectangle(gbr, New Rectangle(0, 0, Me.Width, Me.Height))
End Sub


but this isn't working... the backcolor in both is always white.

can someone help? thanks in advance ;)
 
T

Tom Dacon

I don't know about the rich text box, but my understanding is that the
textbox is actually painted by the container it resides in, so the control's
OnPaint method never actually gets called. I believe that there are several
controls that fit into this category; I've seen a list, but the only one I
remember is the TextBox.

Tom Dacon
Dacon Software Consulting
 
G

Guest

So, you're telling me that with the paint event a can't do anything... but is
there any other way to do what i need?
 
T

Tom Dacon

One approach would be to develop your text box control as a custom control,
derived from System.Windows.Forms.Control rather than from TextBox or
RichTextBox. You would have to supply through your own code all the
functionality of the TextBox that your application needs, but you would also
get the OnPaintBackground calls that you need. Notice that OnPaintBackground
is the override you should put the gradient code in, not OnPaint
(OnPaintBackground is not called for the TextBox control, either).

This would take a lot of coding, I suppose, but if you really, really need
the gradient background it might be the price you need to pay to get it. I'd
like to think that there was an easier way to do this, and I'll be
interested to see if anyone chimes in with a less labor-intensive approach.

By the way, doesn't the impact on readability of text on a gradient
background bother you? Do you think it might bother your users?

Tom Dacon
Dacon Software Consulting
 
G

Guest

well i guess i'll have to do just that...

Well i want to use really smooth colors just when i get focus in the textbox
to help the user to know where he's typing

thanks for your support ;)
 

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