I tried to change the look of WinForms custom TextBox by overriding OnPaint or/and WndProc method. But in both cases before my method is invoked Windows already draws basic TextBox. What's draw here
And what my method does, it's drawing on top of it.
So do you know any solution to this problem ?
Documentation says that it could be unachievable (link below:) https://learn.microsoft.com/en-us/dotnet/framework/winforms/controls/constituent-controls
public class TestTextBox : TextBox
{
public TestTextBox() : base ()
{
SetStyle(ControlStyles.UserPaint, true);
InitializeComponents();
}
protected override void OnPaint(PaintEventArgs e)
{
// base.OnPaint(e);
e.Graphics.DrawLine(new Pen(Color.Blue),10,10,70,10);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
// base.OnPaintBackground(pevent);
pevent.Graphics.DrawLine(new Pen(Color.Red),10,10,90,10);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_PAINT)
{
Graphics g = this.CreateGraphics();
g.DrawLine(new Pen(Color.BlueViolet), 10, 10, 70, 10);
}
else
{
base.WndProc(ref m);
}
}
private void InitializeComponents()
{
this.BackColor = Color.Black;
this.ForeColor = Color.White;
}
}