how to stop flickering C# winforms

前端 未结 16 2325
故里飘歌
故里飘歌 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:36

    I know this is really old question but maybe someone will find it useful.
    I'd like to make little enhancement to viper's answer.

    You can make simple extension to Panel class and hide setting property through reflection.

    public static class MyExtensions {
    
        public static void SetDoubleBuffered(this Panel panel) {
            typeof(Panel).InvokeMember(
               "DoubleBuffered",
               BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty,
               null,
               panel,
               new object[] { true });
        }
    }
    

    If your Panel variable's name is myPanel you can just call
    myPanel.SetDoubleBuffered();
    and that's it. Code looks much cleaner.

提交回复
热议问题