using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace MathematicsDELUXE
{
public static class LabelToButton
{
public static Dictionary<Label, Color[]> LbColors = new Dictionary<Label, Color[]>();
public static void ToButton(this Label l, Color BGTop, Color BGBottom, Color BGTopHover, Color BGBottomHover)
{
l.GradientBackground(BGTop, BGBottom, true);
l.MouseMove += new MouseEventHandler(Move);
l.MouseLeave += new EventHandler(Leave);
Color[] cols = {BGTop, BGBottom, BGTopHover, BGBottomHover};
LbColors.Add(l, cols);
}
private static void Move(object sender, MouseEventArgs e)
{
try
{
Label l = (Label)sender;
l.GradientBackground(LbColors[l][2], LbColors[l][3], true);
}
catch
{
}
}
private static void Leave(object sender, EventArgs e)
{
try
{
Label l = (Label)sender;
l.GradientBackground(LbColors[l][0], LbColors[l][1], true);
}
catch
{
}
}
public static void GradientBackground(this Control c, Color col1, Color col2, bool vertical)
{
Bitmap b;
if (vertical)
{
b = new Bitmap(1, 2);
b.SetPixel(0, 0, col1);
b.SetPixel(0, 1, col2);
}
else
{
b = new Bitmap(2, 1);
b.SetPixel(0, 0, col1);
b.SetPixel(1, 0, col2);
}
c.BackgroundImageLayout = ImageLayout.Stretch;
c.BackgroundImage = b;
}
}
}