This repository has been archived on 2024-08-06. You can view files and clone it, but cannot push or open issues or pull requests.
linear-app-launcher/FizzyLauncher.UI/RyzStudio/Windows/Forms/TImageBox.cs

85 lines
2.9 KiB
C#
Raw Normal View History

2020-04-27 12:17:13 +00:00
using System;
using System.ComponentModel;
using System.Drawing;
namespace RyzStudio.Windows.Forms
{
public class TImageBox : System.Windows.Forms.PictureBox
2020-04-27 12:17:13 +00:00
{
public TImageBox() : base()
2020-04-27 12:17:13 +00:00
{
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();
}
2021-06-01 08:15:08 +00:00
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Color BackColor { get => base.BackColor; set => base.BackColor = value; }
2020-04-27 12:17:13 +00:00
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Image Image { get => base.Image; set => base.Image = value; }
2020-04-27 12:17:13 +00:00
2021-06-01 08:15:08 +00:00
[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;
2020-04-27 12:17:13 +00:00
[Category("Appearance"), Browsable(true)]
public Image ImageNormal { get; set; }
2020-04-27 12:17:13 +00:00
[Category("Appearance"), Browsable(true)]
public Image ImageHover { get; set; }
[Category("Appearance"), Browsable(true)]
public Image ImageSelected { get; set; }
2021-06-01 08:15:08 +00:00
[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;
2020-04-27 12:17:13 +00:00
protected override void OnMouseEnter(EventArgs e)
{
this.Image = this.ImageHover;
2021-06-01 08:15:08 +00:00
this.BackColor = this.BackColorHover;
2020-04-27 12:17:13 +00:00
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(EventArgs e)
{
this.Image = (this.IsSelected ? this.ImageSelected : this.ImageNormal);
2021-06-01 08:15:08 +00:00
this.BackColor = (this.IsSelected ? this.BackColorSelected : this.BackColorNormal);
2020-04-27 12:17:13 +00:00
base.OnMouseLeave(e);
}
protected override void OnLostFocus(EventArgs e)
{
this.Image = (this.IsSelected ? this.ImageSelected : this.ImageNormal);
2021-06-01 08:15:08 +00:00
this.BackColor = (this.IsSelected ? this.BackColorSelected : this.BackColorNormal);
2020-04-27 12:17:13 +00:00
base.OnLostFocus(e);
}
2020-04-27 12:17:13 +00:00
}
}