leocb / MaterialSkin

Theming .NET WinForms, C# or VB.Net, to Google's Material Design Principles.
MIT License
439 stars 131 forks source link

Drawer not showing icons after inserting new tab at runtime #364

Open onlytropics opened 2 years ago

onlytropics commented 2 years ago

I am using the drawer with the flag ShowIconsWhenHidden set (although that shouldn't make a difference really). After the user did some input, a new Tab is created at runtime and inserted after the currently active tab. At this point, the currently active Tab and all the following ones do not display their icons anymore.

Looked at the source code and found the private method preProcessIcons, which I guessed had something to do with it. It is called when ShowIconsWhenHidden is modified so I tried

f.DrawerShowIconsWhenHidden = false;
f.DrawerShowIconsWhenHidden = true;

after inserting the new tab and it definitely helps. Now only the current tab and the new tab's icons are missing.

I had to change MaterialDrawer.cs lines 288-290 to

iconsBrushes[tabPage.ImageKey] = textureBrushGray;
iconsSelectedBrushes[tabPage.ImageKey] = textureBrushColor;
iconsSize[tabPage.ImageKey] = new Rectangle(0, 0, iconRect.Width, iconRect.Height);

as the Add() which was there previously throws an Exception if the key already exists, essentially making calling preProcessIcons more than once impossible.

It also seems that the tabs can't share icons? It seems if I set more than one tab to the same Icon ID, they are not displayed.

valimaties commented 2 years ago

368 will allow you to set the same icon on multiple tab pages, because it adds the icon from the iconlist in the dictionary by concatenate the ImageKey with TabPage's name.

I hope @orapps44 to merge it.

Edit: I suggest (as @leocb said) to use something else for WinForms, or to switch to WPF or something else, as long as this project I don't think it will be maintained anymore. 😌

leocb commented 2 years ago

I yolo merged it. Not sure when another version will be uploaded to nuget, but feel free to compile it and use it yourself