开发者

Double buffering control causes grey to appear

开发者 https://www.devze.com 2023-02-27 01:22 出处:网络
I have a class that accepts a Control and draws generated images to it. In my application code I\'m using a Panel control开发者_JS百科 for this - which seems to work well, except that I get a lot of f

I have a class that accepts a Control and draws generated images to it. In my application code I'm using a Panel control开发者_JS百科 for this - which seems to work well, except that I get a lot of flickering on the control as the image is redrawn. I think the solution is to enable double buffering on the control. I'm doing this with the following code:

System.Reflection.PropertyInfo aProp =
                typeof(System.Windows.Forms.Control).GetProperty(
                    "DoubleBuffered",
                    System.Reflection.BindingFlags.NonPublic |
                    System.Reflection.BindingFlags.Instance);

            aProp.SetValue(drawControl, true, null); 

After adding this code, the image is drawn, and then immeadiately replaced with the default grey button background colour - it's as if the system is drawing over my own content.

I remember seeing somewhere a property that tells the system to never draw the control (which would be perfect for me since I'm filling the entire control with content), but now I cannot find it. Is there such a property, and if so, how can I enable it?

I'm using C# with the .NET framework ver 4.0.


Try setting FlatStyle on the control to FlatStyle.Standard, if it's currently set to FlatStyle.System.

(Setting DoubleBuffered by reflection looks horrible too, but perhaps you need to do that for some reason)

0

精彩评论

暂无评论...
验证码 换一张
取 消