TextBox OnPaint override issues

  • Thread starter Thread starter DeveloperX
  • Start date Start date
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
}
}
 
DeveloperX said:
[overridden OnPaint not called for derived TextBox]

Try adding this to your derived constructor:

this.SetStyle(ControlStyles.UserPaint, true);

Eq.
 
Back
Top