how to stop flickering C# winforms

前端 未结 16 2117
故里飘歌
故里飘歌 2020-11-28 04:16

I have a program that is essentially like a paint application. However, my program has some flickering issues. I have the following line in my code (which should get rid of

相关标签:
16条回答
  • 2020-11-28 04:51

    if all of the above doesn't work you can always create your own double buffer link to Microsofts tutorial: https://docs.microsoft.com/en-us/dotnet/framework/winforms/advanced/how-to-reduce-graphics-flicker-with-double-buffering-for-forms-and-controls

    hopes it works for you

    0 讨论(0)
  • 2020-11-28 04:55

    If memory is tight (so you don't want the memory cost of double-buffering), one possible way to REDUCE, though not eliminate, flicker, is to set background color to the dominant color in your current scene.

    Why this helps: flicker is a momentary flash of the background color, which the OS draws before drawing child controls or your custom drawing code. If that flash is a color that is closer to the final color to be displayed, it will be less noticeable.

    If you are not sure what color to start with, start with 50% gray, because this is an average of black and white, so will be closer to most colors in your scene.

    myFormOrControl.BackColor = Color.Gray;
    
    0 讨论(0)
  • 2020-11-28 04:56

    I'd advise overriding OnPaintBackground and handling the background erase yourself. If you know you are painting the whole control you can just do nothing in OnPaintBackground (don't call the base method) and it will prevent the background colour being painted first

    0 讨论(0)
  • 2020-11-28 04:57

    Can you try using a timer and boolean to check if mouse is down, and paint in that spot, using a variable again check if user has moved his mouse, if moved paint that spot too etc.

    Or just check if mouse down(via boolean that sets true when mouse is down) using a timer and paint it considering you are probably trying to just paint one pixel, not like you have shadow etc. Instead of using actual mousedown. So you check every 1 second instead of 0.0001 and it wont flicker. Or vice-versa, try it with your own times.

    0 讨论(0)
提交回复
热议问题