Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBox OnPaint method is not called?

I have use the following code to create a textbox, but the paint method is not triggered at any situation of the textbox. Can you suggest a solution to trigger the OnPaint() ?

public class MyTextBox : TextBox
{
    protected override void OnPaintBackground(PaintEventArgs pevent)
    {
        base.OnPaintBackground(pevent);
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        ControlPaint.DrawBorder(e.Graphics,this.Bounds, Color.Red,ButtonBorderStyle.Solid);
        base.OnPaint(e);
    }

    protected override void OnTextChanged(EventArgs e)
    {
        this.Invalidate();
        this.Refresh();
        base.OnTextChanged(e);
    }
}
like image 866
Venkatesh Ks Avatar asked Nov 29 '22 06:11

Venkatesh Ks


1 Answers

OnPaint will not be called on a TextBox by default unless you register it as a self-painting control, by making a call to :

SetStyle(ControlStyles.UserPaint, true);

e.g. from your MyTextBox constructor.

like image 190
Ben Jackson Avatar answered Dec 10 '22 14:12

Ben Jackson