using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection;
using System.IO;

namespace Mesnac.Controls.Default
{
    [ToolboxBitmap(typeof(SpecialButton), "Resources.NewButton1.png")]
    public partial class SpecialButton : Button
    {
        #region 字段定义

        protected Assembly _assembly = Assembly.GetExecutingAssembly();
        protected Stream _imageStream;

        #endregion

        #region 构造方法

        public SpecialButton()
        {
            InitializeComponent();
            this.Size = new Size(158, 54);
            this.BackColor = Color.Transparent; //背景透明
            this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;   //显示样式
            this.FlatAppearance.BorderSize = 0; //边框为0
            this.FlatAppearance.MouseOverBackColor = Color.Transparent;
            this.FlatAppearance.MouseDownBackColor = Color.Transparent;
            this.TextAlign = ContentAlignment.MiddleCenter; //文字对齐
            this.Font = new System.Drawing.Font("黑体", 12, FontStyle.Bold); //设置字体
            this.ForeColor = Color.White; //文字颜色
            _imageStream = _assembly.GetManifestResourceStream("Mesnac.Controls.Default.Resources.NewButton1.png");
            this.BackgroundImage = Image.FromStream(_imageStream);
            this.BackgroundImageLayout = ImageLayout.Stretch;
            this.MouseMove += new System.Windows.Forms.MouseEventHandler(btnMouseMove);
            this.MouseLeave += new System.EventHandler(btnMouseLeave);
        }

        public SpecialButton(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        #endregion

        #region 事件处理

        private void btnMouseMove(object sender, MouseEventArgs e)
        {
            _imageStream = _assembly.GetManifestResourceStream("Mesnac.Controls.Default.Resources.NewButton2.png");
            this.BackgroundImage = Image.FromStream(_imageStream);
        }

        private void btnMouseLeave(object sender, EventArgs e)
        {
            _imageStream = _assembly.GetManifestResourceStream("Mesnac.Controls.Default.Resources.NewButton1.png");
            this.BackgroundImage = Image.FromStream(_imageStream);
        }

        #endregion
    }
}