Krypton-Suite-Legacy-Archive / Krypton-NET-5.470

A update to Component factory's krypton toolkit to support the .NET 4.7 framework.
BSD 3-Clause "New" or "Revised" License
78 stars 20 forks source link

Ribbon NumericUpDown not disabling. #141

Open Tape-Worm opened 5 years ago

Tape-Worm commented 5 years ago

I have 2 numeric up down controls on the ribbon, along with 2 labels.

On startup of my application, these labels and numerics should be disabled. But, only the labels are disabled.

image

If I change the Enabled state on the numeric by clicking the "Fixed Size" button, the numerics will disable just fine.

I've walked through the code with the debugger to ensure that the Enabled flag is being set to False at startup (this also happens if I set Enabled to False in the designer), and it is being set (and the property returns False as it should), yet they are still enabled.

All other control types that I have on the ribbon behave properly, so far, only the numeric is not behaving correctly.

Tape-Worm commented 5 years ago

And ... now.. for some reason, it's working. I have no idea why. I'm going to close this for now since it's working as it should.

Tape-Worm commented 5 years ago

OK, so, for some inexplicable reason, the numerics are no longer staying disabled again on startup.

Here's the weirdness of it all: I had the numerics disabled in the IDE. I run the app, and go to the tab and the numerics are enabled (they shouldn't be). So, I enable them in the IDE, and now they're disabled on startup (as they should be). When I originally opened this issue, I had the opposite problem. And disabling them in the IDE worked (even though I'm setting .Enabled = false in the code!)

This is quite schizophrenic.

Tape-Worm commented 5 years ago

OK, so I just ran the Ribbon Controls 2019 demo, and disabled the numericUpDown1 on the ribbon: image

And when I run the code: image

It also does not appear to respect the ReadOnly property either.

Tape-Worm commented 5 years ago

So, digging through KryptonRibbonGroupNumericUpDown.cs, I noticed that the Enabled property uses an internal private variable to store its state. This is fine, but the underlying control is not updated.

It looks like it gets updated at runtime via the PropertyChanged event, but not on initialization. So basically, by setting Enabled = false in the designer, we end up with a control wrapper that is out of sync with it's underlying control. This would explain the really crazy behavior I saw (beyond that of not respecting the flag - weird flashing everytime the property was set, big performance hits, etc...)

For giggles, I added this to the enabled property (after the _enabled assignment): NumericUpDown.Enabled = value;

That seems to have cleared up the issue. To fix this, I'd probably get rid of the internal private variable tracking the enabled state, and just use the Enabled property on the underlying control as a mirror. Same with any other property exposed. And any property that does not fit the context of the control wouldn't be exposed at all.

Of course, my concern here is that if the state flag is removed and replaced with the underlying Enabled property, what will it break? Was it done this way for a specific purpose?