Open kachnitata opened 3 hours ago
I can rewrite the code, piece by piece, when I find some spare time. But perhaps someone of you guys comes up with a better solution...
also, the recently added ControlStatusStorage/ControlStatusInfo
might be used to track whether the handlers have already been attached, and prevent adding them the second time.
on the beginning of ThemeControl()
there is
var info = controlStatusStorage.GetControlStatusInfo(control);
so, we may add
bool shouldAttachHandlers = info == null;
and later in the code, something like
if(shouldAttachHandlers) grid.Paint += (object sender, PaintEventArgs e) => {... }
etc... but there are other handlers attached outside of this method....
While the capability to switch the theme on the fly is a great improvement, I am not happy with the way it is implemented. When I try to switch dark/light theme multiple times, each time new event handlers are added. So, for example, when I put a breakpoint into the handler of a
DataGridView
the first time it was executed once. but when I switched the theme, it was attached again and executed twice. And the next time three times, etc..
For controls that are nested deeper, this number can potentially grow as higher power of number of execution because of
control.HandleCreated +=
,control.ControlAdded +=
etc. (not tested).I think a better solution would be to extract all the handlers to methods or local functions and explicitly detach them before attaching them, like
rewriting the code would of course take some time as there are many places like this...