I have a winform, and during LOAD it calls a textbox backcolor change which fires the paint event - my code never reaches the lines after that textbox colour change and I've noticed during step-through that the paint event is looping loads of times. What's happening here? Is VS realising I'm stuck in an infinite paint loop and just skipping the broken Load code for me?
public Pretty_Load()
{
textBox1.BackColor = Color.FromArgb(230, 255, 255, 255);
/* Other lines that aren't reached */
}
Here's the paint event which loops many times before just giving up.
private void Pretty_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Point p1 = this.ClientRectangle.Location;
Point p2 = new Point(this.ClientRectangle.Right, this.ClientRectangle.Bottom);
using (LinearGradientBrush brsGradient = new LinearGradientBrush(p1, p2, Color.FromArgb(64, 64, 100), Color.FromArgb(32,0,0)))
{
g.FillRectangle(brsGradient, e.ClipRectangle);
}
}
I'm adding the paint event handler during the Pretty
form constructor:
public Pretty()
{
InitializeComponent();
this.Paint += Pretty_Paint;
/* Some other things and backcolor changes.
}
I suspect that maybe I've setup the handler wrong, or the looping is actually part of the "other things" color changes during the constructor that are all just happening during the textbox1.BackColor
change