Paint net5/25/2023 ![]() private void OnPaint(object sender, PaintEventArgs e) This handler calls a custom routine that does the actual painting. A custom control I am developing draws its whole contents via handling the Paint event. I found the Invalidate() creating too much of flickering. Whenever you use it, you should ask yourself if you shouldn't be using a Thread instead. The most common scenario for Update() is when you change a property (say, label1.Text, which will invalidate the Label) in a for-loop and that loop is temporarily blocking the Message-Loop. That is efficient because when something changes that usually cascades into other things (controls) changing as well. The normal way Windows (Win32 and WinForms.Net) handles this is to wait for the MessageQueue to run empty and then process all invalidated screen areas. If you're in a hurry you should call Refresh() but then you run the risk that it will be repainted several times consecutively because of other controls (especially the Parent) Invalidating. Normally, you would just call Invalidate() and let the system combine that with other Screen updates. This.Refresh() // Combines Invalidate() and Update() This.Update() // forces Repaint of invalidated area In a method of your Form or Control, you have 3 choices: this.Invalidate() // request a delayed Repaint by the normal MessageLoop system
0 Comments
Leave a Reply. |