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);
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With