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
}
}
Paul E Collins - 03 Jan 2007 11:31 GMT
> [overridden OnPaint not called for derived TextBox]
Try adding this to your derived constructor:
this.SetStyle(ControlStyles.UserPaint, true);
Eq.
DeveloperX - 03 Jan 2007 11:41 GMT
Cheers Paul, got there just as you posted :) I also found:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=26542&SiteID=1
which covers painting in the non client area as well for anyone who's
interested.
> > [overridden OnPaint not called for derived TextBox]
>
[quoted text clipped - 3 lines]
>
> Eq.
DeveloperX - 03 Jan 2007 11:32 GMT
Solved it...
http://www.codeproject.com/cs/miscctrl/alphablendtextbox.asp
> 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
[quoted text clipped - 21 lines]
> }
> }