ITsiIconItem.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using BulePointLilac.Controls;
  2. using BulePointLilac.Methods;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace ContextMenuManager.Controls
  6. {
  7. interface ITsiIconItem
  8. {
  9. ChangeIconMenuItem TsiChangeIcon { get; set; }
  10. string IconLocation { get; set; }
  11. string IconPath { get; set; }
  12. int IconIndex { get; set; }
  13. Image Image { get; set; }
  14. Icon ItemIcon { get; }
  15. }
  16. sealed class ChangeIconMenuItem : ToolStripMenuItem
  17. {
  18. public ChangeIconMenuItem(ITsiIconItem item) : base(AppString.Menu.ChangeIcon)
  19. {
  20. this.Click += (sender, e) =>
  21. {
  22. string iconPath = item.IconPath;
  23. int iconIndex = item.IconIndex;
  24. using(Icon icon = ChangeIcon(ref iconPath, ref iconIndex))
  25. {
  26. if(icon == null) return;
  27. item.IconPath = iconPath;
  28. item.IconIndex = iconIndex;
  29. item.IconLocation = $"{iconPath},{iconIndex}";
  30. item.Image = icon.ToBitmap();
  31. }
  32. };
  33. }
  34. public static Icon ChangeIcon(ref string iconPath, ref int iconIndex)
  35. {
  36. using(IconDialog dlg = new IconDialog { IconPath = iconPath, IconIndex = iconIndex })
  37. {
  38. if(dlg.ShowDialog() != DialogResult.OK) return null;
  39. iconPath = dlg.IconPath;
  40. iconIndex = dlg.IconIndex;
  41. }
  42. return ResourceIcon.GetIcon(iconPath, iconIndex);
  43. }
  44. }
  45. }