I ‘ve had a couple of bug reports for the incorrect drawing of Krypton controls when there is a deep nesting of controls under Windows 7 64bit. You can see what I mean in the following image that shows a test application that has 8 KryptonNavigator instances all inside each other.

Incorrect drawing

I spent a couple of different attempts investigating this with no luck. No matter what I did and how I looked at the scenario the Krypton code did not seem to be doing anything wrong. Fortunately someone spotted a Microsoft Knowledge Base article describing this issue and presenting a workaround. You can read it here.

The solution to the above problem was to add the following new control and then replace the 4th instance of the KryptonNavigator with the new KryptonNavigatorDelay class.

 public class KryptonNavigatorDelay : KryptonNavigator
 {
   protected override void OnSizeChanged(EventArgs e)
   {
     if (Handle != null)
       BeginInvoke((MethodInvoker)delegate
          { base.OnSizeChanged(e); });
   }
 }

This results in the following appearance when resizing the window at runtime.

Correct drawing

The issue is with the operating system and seems to manifest itself under Windows 7 64bit when you have a depth of around 16 deep. Testing with various different controlsdoes not seem to make much difference in the depth required to see problems. Apparently the same problem can occur under 32bit operating systems but not until you have a much deeper level of nesting. Hence you are only likely to have encountered this problem under 64bit.

I cannot simply at the above code to every Krypton container because the solution causes a delay when drawing the control as the BeginInvoke delays execution of the delegate until the current windows message has been completed. So if you experience the issue then you need to check your nesting depth and look at implementing the work around at an appropriate level in the control hierarchy.

3 Responses to “Deep nesting and redrawing”

  1. Sven Says:

    Thanks for this post Phil. We have this issue in our application and have spent a lot of time to find the source for this bug without success. But finally… Thanks Phil =)

  2. Brent Says:

    Many thanks for digging in to this since I haven’t made the time to do so!

  3. Alex Says:

    Thank you for publishing this. I have been frustrated by it, as well

Leave a Reply