TextBox OnPaint override issues

D

DeveloperX

Hi, I'm a little confused regarding the OnPaint override for a textbox
(code to follow). I have a tiny test class which inherits from TextBox
and overrides OnPaint. However OnPaint in my derived class is never
called. Could someone be so kind as to explain where I'm going wrong?
I've got some ideas, I believe the textbox is a wrapper around the
win32 textbox, so perhaps I need to override the wndproc, but even so
I'd still expect my OnPaint to get called...
Thanks

public class DTextBox : System.Windows.Forms.TextBox
{
public DTextBox()
{
}
protected override void OnPaint(PaintEventArgs e)
{
Console.WriteLine("s");
//base.OnPaint(e);
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
Console.WriteLine("d");
this.Invalidate(); //trying to force OnPaint
}
}
 
P

Paul E Collins

DeveloperX said:
[overridden OnPaint not called for derived TextBox]

Try adding this to your derived constructor:

this.SetStyle(ControlStyles.UserPaint, true);

Eq.
 

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