using System; using System.ComponentModel; using System.Drawing; namespace RyzStudio.Windows.Forms { public class TImageBox : System.Windows.Forms.PictureBox { public TImageBox() : base() { this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.ErrorImage = null; this.InitialImage = null; this.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage; } protected override void OnCreateControl() { OnMouseLeave(null); base.OnCreateControl(); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new Color BackColor { get => base.BackColor; set => base.BackColor = value; } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public new Image Image { get => base.Image; set => base.Image = value; } [Category("Appearance"), Browsable(true)] public Color BackColorNormal { get; set; } = Color.Transparent; [Category("Appearance"), Browsable(true)] public Color BackColorHover { get; set; } = Color.Transparent; [Category("Appearance"), Browsable(true)] public Color BackColorSelected { get; set; } = Color.Transparent; [Category("Appearance"), Browsable(true)] public Image ImageNormal { get; set; } [Category("Appearance"), Browsable(true)] public Image ImageHover { get; set; } [Category("Appearance"), Browsable(true)] public Image ImageSelected { get; set; } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public Image NormalImage { get => this.ImageNormal; set => this.ImageNormal = value; } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public Image HoverImage { get => this.ImageHover; set => this.ImageHover = value; } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public Image SelectedImage { get => this.ImageSelected; set => this.ImageSelected = value; } public bool IsSelected { get; set; } = false; protected override void OnMouseEnter(EventArgs e) { this.Image = this.ImageHover; this.BackColor = this.BackColorHover; base.OnMouseEnter(e); } protected override void OnMouseLeave(EventArgs e) { this.Image = (this.IsSelected ? this.ImageSelected : this.ImageNormal); this.BackColor = (this.IsSelected ? this.BackColorSelected : this.BackColorNormal); base.OnMouseLeave(e); } protected override void OnLostFocus(EventArgs e) { this.Image = (this.IsSelected ? this.ImageSelected : this.ImageNormal); this.BackColor = (this.IsSelected ? this.BackColorSelected : this.BackColorNormal); base.OnLostFocus(e); } } }