main
 1using System;
 2using System.Drawing;
 3using System.Windows.Forms;
 4using Gorilla.Commons.Infrastructure.Container;
 5
 6namespace MoMoney.Presentation.Winforms.Helpers
 7{
 8    static public class ButtonExtensions
 9    {
10        static public Button will_be_shown_as(this Button button, Bitmap image)
11        {
12            BitmapRegion.CreateControlRegion(button, image);
13            button.MouseLeave += (sender, e) => BitmapRegion.CreateControlRegion(button, image);
14            button.FlatAppearance.BorderSize = 0; //needs to be here so edges don't get affected by borders
15            return button;
16        }
17
18        static public Button when_hovered_over_will_show(this Button button, Bitmap image)
19        {
20            button.MouseEnter += (sender, e) => BitmapRegion.CreateControlRegion(button, image);
21            return button;
22        }
23
24        static public Button will_execute<Command>(this Button button, Func<bool> when) where Command : gorilla.commons.utility.Command
25        {
26            button.Click += (sender, e) =>
27            {
28                if (when()) Resolve.the<Command>().run();
29            };
30            button.Enabled = when();
31            return button;
32        }
33
34        static public Control with_tool_tip(this Control control, string title, string caption)
35        {
36            var tip = new ToolTip
37                      {
38                          IsBalloon = true,
39                          ToolTipTitle = title,
40                          ToolTipIcon = ToolTipIcon.Info,
41                          UseAnimation = true,
42                          UseFading = true,
43                          AutoPopDelay = 10000,
44                      };
45            tip.SetToolTip(control, caption);
46            control.Controls.Add(new ControlAdapter(tip));
47            return control;
48        }
49    }
50}