0

I have found a flickering problem in the WinForms .NET TreeView while working with one of a legacy project in Windows 11. It turned out that the problem can be easily reproduced in a brand-new WinForms project for .NET Framework (I used the v4.7.2). First create a TreeView with two root nodes, each with a couple of subnodes. Then create an ImageList with the color depth set to 8, 16 or 24 bits and upload one 16x16 image to it. Finally, attach this ImageList to our TreeView and launch the project:

enter image description here

If we expand the root nodes and move the mouse pointer over the root tree line containing the plus/minus buttons, the nodes at the right of the mouse pointer start to flicker.

During my experiments I found that this problem occurs only in Windows 11 - all is ok in Windows 10. And the problem goes away if I set the ImageList color depth to 32 bit.

I tried to play with double buffering using answers for this question, but they didn't help. What it could be and how to eliminate this flickering effect?

TecMan
  • 2,743
  • 2
  • 30
  • 64
  • 1
    *the problem goes away if I set the ImageList color depth to 32 bit*: that's what you should use in any case, so what is the actual problem? – Jimi Oct 12 '22 at 15:39
  • @Jimi, how to fix the problem if we use a color depth less than 32 bits? I also thought about switching to 32-bit depth in all ImageLists. Could there be any side effects after doing this? – TecMan Oct 12 '22 at 15:45
  • Yes, 32 bit is the right color depth here. For the DoubleBuffered part, https://stackoverflow.com/a/10364283/14171304. Note, you should set the color depth before adding the images. See [this](https://stackoverflow.com/a/33469823/14171304). – dr.null Oct 12 '22 at 15:48
  • The side effect is that the bitmaps are then rendered the way it's supposed to be – Jimi Oct 12 '22 at 15:54
  • @Jimi, one of the 'side effects' for 32-bit icons (for example, PNG images with semi-transparent pixels) is that the pixels with transparency become black pixels if the app is not rendered with the OS visual styles (for example, they are turned in the OS). Can we have something like that for old GIF images with their palettes and transparent pixels if we will upload them to an ImageList with the 32-bit color depth? – TecMan Oct 13 '22 at 08:04

0 Answers0