main
1using System;
2using System.Drawing;
3using System.IO;
4using Gorilla.Commons.Infrastructure.Reflection;
5
6namespace MoMoney.Presentation.Winforms.Resources
7{
8 public class ApplicationIcon : IDisposable
9 {
10 readonly Icon underlying_icon;
11
12 public ApplicationIcon(string name_of_the_icon, Action<ApplicationIcon> action)
13 {
14 this.name_of_the_icon = name_of_the_icon;
15 if (icon_can_be_found())
16 {
17 action(this);
18 underlying_icon = new Icon(find_full_path_to(this));
19 }
20 }
21
22 public string name_of_the_icon { get; private set; }
23
24 public virtual void Dispose()
25 {
26 if (underlying_icon != null) underlying_icon.Dispose();
27 }
28
29 static public implicit operator Icon(ApplicationIcon icon_to_convert)
30 {
31 return icon_to_convert.underlying_icon;
32 }
33
34 protected string find_full_path_to(ApplicationIcon icon_to_convert)
35 {
36 return Path.Combine(icon_to_convert.startup_directory() + @"\icons", icon_to_convert.name_of_the_icon);
37 }
38
39 protected bool icon_can_be_found()
40 {
41 return File.Exists(find_full_path_to(this));
42 }
43 }
44}