반응형
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DzERD.CustomControls.Common
{
    public class ImageButtonER : Button
    {

        Image _click;
        Image _nomal;
        Image _hover;
        Image _disable;



        public Image Click1
        {
            get { return _click; }
            set { _click = value; }
        }

        public Image Hover
        {
            get { return _hover; }
            set { _hover = value; }
        }

        public Image Nomal
        {
            get { return _nomal; }
            set { _nomal = value; }
        }
        public Image Disable
        {
            get { return _disable; }
            set { _disable = value; }
        }


        public ImageButtonER()
        {
            this.BackColor = Color.Transparent;
            this.BackgroundImageLayout = ImageLayout.Stretch;
            this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            if (this.Nomal != null)
            {
                this.BackgroundImage = Nomal;

            }
            this.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255);

        }

        protected override bool ShowFocusCues
        {
            get
            {
                return false;
            }
        }

        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
            this.BackgroundImage = Hover;
        }

        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);
            this.BackgroundImage = Nomal;
        }

        protected override void InitLayout()
        {
            base.InitLayout();
            if(this.Nomal != null)
            {
                this.BackgroundImage = Nomal;
            }
        }

        protected override void OnMouseHover(EventArgs e)
        {
            this.BackgroundImage = _hover;
            this.Refresh();
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            this.BackgroundImage = _hover;
            this.Refresh();
        }

        protected override void OnMouseUp(MouseEventArgs mevent)
        {
            this.BackgroundImage = _hover;
            this.Refresh();
            base.OnMouseUp(mevent);
        }

        protected override void OnMouseDown(MouseEventArgs mevent)
        {
            this.BackgroundImage = _click;
            this.Refresh();
            base.OnMouseDown(mevent);
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            this.BackgroundImage = _nomal;
            this.Refresh();
        }

        protected override void OnEnabledChanged(EventArgs e)
        {
            if (this.Enabled)
            {
                this.BackgroundImage = _nomal;
            }
            else
            {
                this.BackgroundImage = _disable;
            }

            base.OnEnabledChanged(e);
        }

        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            base.OnPaintBackground(pevent);
        }

    }
}

+ Recent posts