0

I have designed a WinForms app with a several (nested) TableLayoutPanel containing background images and colors indicating status of hardware components. I added a PropertyGrid to display content of a specific object using the ComponentModel.

Example:

public class MyObject
{
    public float Voltage;

    [Category("Operation Voltage")]
    [Description("Voltage applied")]
    [DisplayName("Voltage")]
    public float Vop { get => Voltage; }
}

I add the object to a PropertyGrid (the example is nonsense - only for illustration)

MyObject m = new MyObject();
m.Voltage = 1.234;
propertyGrid1.SelectedObject = m;

All works fine so far until I actively select the value in the PropertyGrid the actual value, selecting the category header has no side effect). If I do so, most TableLayoutPanel in my app start to flicker.

The problem is caused by (which I need for other purposes) this method described here:

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
            return cp;
        }
    }

Following this article here which describes the issue in my opinion I am supposed to release the "device context". Can anyone point out how to do that in case of a PropertyGrid?

benJima
  • 99
  • 1
  • 7
  • Are you sure this:`public float Vop { get => Vop; }` is correct? Doesn't it look like a little *recursive*? Have you misspelled a backing field, maybe? – Jimi Apr 16 '20 at 11:55
  • You are right. My mistake. I have edited the example. I know it makes no sense to have a field to access a variable which is public anyway. But I need this structure for further SQL usage. – benJima Apr 16 '20 at 12:43
  • See that you don't have other properties that have a getter that returns itself recursively. The PropertyGrid doesn't cause the problem, it's itself a *victim*. If you have some *flickering*, it's probably caused by handling Graphics procedures the wrong way. – Jimi Apr 16 '20 at 12:49

0 Answers0