Like you are probably aware, .NET raises the Paint Event every time just about anything changes. And many times, it takes a little work to get a desired visual effect to work. Well, beware of what you put and where you put it. First of all, don't ever use any Console.Read or Console.Readline statements in any Event Handlers, in most cases they will block the program from continuing. But a more common one is calling MessageBox.Show. Many folks, particularly those that don't like using Assertions, use MessageBoxes to display information and/or get a program to pause. It's a bad programming technique, but not an uncommon one. Well execute this bit of code:
| public static void Main(){ Form frmMain = new Form(); frmMain.Text = "This is an example of what not to do"; frmMain.BackColog = Color.White; frmMain.Paint = new PaintEventHandler (CustomPaintHandler); } |
| public static CustomPaintHandler(object sender, PaintEventArgs pea){ MessageBox.Show(this.Text); } |