⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagebutton.cs

📁 POCKET PC,照片管理系统!提供了真正意义上的目录打开功能
💻 CS
字号:
using System;

#if DESIGNTIME
	[assembly: System.CF.Design.RuntimeAssemblyAttribute("ImageButton, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
#endif

namespace Addot.Windows.Forms
{
	/// <summary>
	/// Implements a Button control displaying an image.
	/// This class can be registered in the Visual Studio .Net control library.
	/// </summary>
	public class ImageButton : System.Windows.Forms.Control
	{
        #region --- Fields ---
        private System.Drawing.Image image;
        private System.Drawing.Image imagePressed;
        private System.Windows.Forms.ImageList imageList;
        private int imageIndex;
        private int imagePressedIndex;
        private bool isPressed; 
        #endregion
        
        #region --- Properties ---
#if DESIGNTIME
		[System.ComponentModel.Category("Custom")]
		[System.ComponentModel.DefaultValueAttribute("")]
		[System.ComponentModel.Description("ImageList containing the button images")]
#endif
        public System.Windows.Forms.ImageList ButtonImageList
        {
            get
            {
                return imageList;
            }
            set
            {
                imageList = value;
            }
        }
#if DESIGNTIME
		[System.ComponentModel.Category("Custom")]
		[System.ComponentModel.DefaultValueAttribute("")]
		[System.ComponentModel.Description("Image of the button when it is not pressed")]
#endif
        public System.Drawing.Image ButtonImage
        {
            get
            {
                return image;
            }
            set
            {
                image = value;
                this.Invalidate();
            }
        }
#if DESIGNTIME
		[System.ComponentModel.Category("Custom")]
		[System.ComponentModel.DefaultValueAttribute("")]
		[System.ComponentModel.Description("Image of the button when it is pressed")]
#endif
        public System.Drawing.Image ButtonPressedImage
        {
            get
            {
                return imagePressed;
            }
            set
            {
                imagePressed = value;
                this.Invalidate();
            }
        }
#if DESIGNTIME
		[System.ComponentModel.Category("Custom")]
		[System.ComponentModel.DefaultValueAttribute("")]
		[System.ComponentModel.Description("Index of the image when the button is not pressed")]
#endif
        public int ButtonImageIndex
        {
            get
            {
                return imageIndex;
            }
            set
            {
                imageIndex = value;
                if( imageList != null )
                {
                    image = imageList.Images[imageIndex];
                    this.Invalidate();
                }
            }
        }
#if DESIGNTIME
		[System.ComponentModel.Category("Custom")]
		[System.ComponentModel.DefaultValueAttribute("")]
		[System.ComponentModel.Description("Index of the image when the button is pressed")]
#endif
        public int ButtonPressedImageIndex
        {
            get
            {
                return imagePressedIndex;
            }
            set
            {
                imagePressedIndex = value;
                if( imageList != null )
                {
                    imagePressed = imageList.Images[imagePressedIndex];
                    this.Invalidate();
                }
            }
        }
        #endregion

        public ImageButton() : base()
		{
			//
			// TODO: Add constructor logic here
			//
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if( isPressed && imagePressed != null)
            {
                e.Graphics.DrawImage(imagePressed, 0, 0);
            }
            else if( image != null )
            {
                e.Graphics.DrawImage(image, 0, 0);
            }

            base.OnPaint(e);
        }

        protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseDown (e);
            isPressed = true;
            this.Invalidate();
        }

        protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseUp (e);
            isPressed = false;
            this.Invalidate();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -