SafeDispatch/Safedispatch_4_0/maptab/UIClasses/MenuButton.cs

454 lines
15 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Dispatcher.maptab
{
public partial class MenuButton : UserControl
{
public enum ThemeStyle { Custom, Teal, Orange, Bordo, Cofee, Aqua, Olive, DarkOrange, Blue, Light };
[Description("Title"), Category("Data")]
public string Title
{
get { return labelName.Text; }
set { labelName.Text = value; }
}
[Description("Image"), Category("Data")]
private Image _image;
public Image Image
{
get { return _image; }
set {
_image = value;
if (!_selected)
{
pictureBox.Image = value;
}
}
}
[Description("Image Selected"), Category("Data")]
private Image _imageSelected;
public Image ImageSelected
{
get { return _imageSelected; }
set
{
_imageSelected = value;
if (_selected)
{
pictureBox.Image = value;
}
}
}
[Description("Background Icon Color"), Category("Color")]
private Color _backgroundIconColor;
public Color BackgroundIconColor
{
get { return _backgroundIconColor; }
set
{
_backgroundIconColor = value;
if (!_selected)
UnSelected();
else
Selected();
//panelLeft.BackColor = value;
//pictureBox.BackColor = value;
}
}
[Description("Background Icon Color Selected"), Category("Color")]
private Color _backgroundIconColorSelected;
public Color BackgroundIconColorSelected
{
get { return _backgroundIconColorSelected; }
set
{
_backgroundIconColorSelected = value;
if (!_selected)
UnSelected();
else
Selected();
//panelLeft.BackColor = value;
//pictureBox.BackColor = value;
}
}
[Description("Background Color"), Category("Color")]
private Color _backgroundColor;
public Color BackgroundColor
{
get { return _backgroundColor; }
set
{
_backgroundColor = value;
if (!_selected)
UnSelected();
else
Selected();
}
}
[Description("Background Color Selected"), Category("Color")]
private Color _backgroundColorSelected;
public Color BackgroundColorSelected
{
get { return _backgroundColorSelected; }
set
{
_backgroundColorSelected = value;
if (!_selected)
UnSelected();
else
Selected();
}
}
[Description("ForeColor Selected"), Category("Color")]
private Color _foreColorSelected;
public Color ForeColorSelected
{
get { return _foreColorSelected; }
set
{
_foreColorSelected = value;
if (_selected)
{
labelName.ForeColor = value;
}
}
}
[Description("ForeColor Selected"), Category("Color")]
private Color _foreColorUnselected;
public Color ForeColorUnselected
{
get { return _foreColorUnselected; }
set
{
_foreColorUnselected = value;
if (!_selected)
{
labelName.ForeColor = value;
}
}
}
[Description("Theme"), Category("Data")]
private ThemeStyle _theme;
public ThemeStyle Theme
{
get { return _theme; }
set { _theme = value;
if (!_selected)
UnSelected();
else
Selected();
}
}
[Description("Select"), Category("Data"), DefaultValue(false), Browsable(true)]
private bool _selected = false;
public bool IsSelected
{
get { return _selected; }
set
{
if (_selectable)
{
_selected = value;
if (!_selected)
UnSelected();
else
Selected();
}
}
}
[Description("IsSelectable"), Category("Data"), DefaultValue(true), Browsable(true)]
private bool _selectable = true;
public bool IsSelectable
{
get { return _selectable; }
set { _selectable = value;
_selected = false;
UnSelected();
}
}
[Description("ToolTip Text"), DefaultValue(""), Category("Data")]
private string _toolTip;
public string ToolTip
{
get { return _toolTip; }
set { _toolTip = value; }
}
public MenuButton()
{
InitializeComponent();
base.BorderStyle = BorderStyle.None;
this.BorderStyle = BorderStyle.None;
//UnSelected();
// create the toolTip that will be displayed
toolTip = new ToolTip();
toolTip.AutoPopDelay = 500;
toolTip.InitialDelay = 500;
toolTip.ReshowDelay = 500;
toolTip.IsBalloon = false;
toolTip.ShowAlways = true;
}
private BorderStyle border;
public new BorderStyle BorderStyle
{
get { return border; }
set
{
border = value;
Invalidate();
}
}
public void Selected()
{
if (_theme != ThemeStyle.Custom)
{
panelBack.BackColor = GetThemeBgColor(_theme, true);
panelLeft.BackColor = GetThemeBgIconColor(_theme, true);
pictureBox.BackColor = panelLeft.BackColor;
labelName.ForeColor = GetForeColor(_theme, true);
labelArrow.ForeColor = GetForeColor(_theme, true);
}
else
{
panelBack.BackColor = BackgroundColorSelected;
panelLeft.BackColor = BackgroundIconColorSelected;
pictureBox.BackColor = BackgroundIconColorSelected;
labelName.ForeColor = ForeColorSelected;
labelArrow.ForeColor = ForeColorSelected;
}
pictureBox.Image = ImageSelected;
}
public void UnSelected()
{
if (_theme != ThemeStyle.Custom)
{
panelBack.BackColor = GetThemeBgColor(_theme, false);
panelLeft.BackColor = GetThemeBgIconColor(_theme, false);
pictureBox.BackColor = panelLeft.BackColor;
labelName.ForeColor = GetForeColor(_theme, false);
labelArrow.ForeColor = GetForeColor(_theme, false);
}
else
{
panelBack.BackColor = BackgroundColor;
panelLeft.BackColor = BackgroundIconColor;
pictureBox.BackColor = BackgroundIconColor;
labelName.ForeColor = ForeColorUnselected;
labelArrow.ForeColor = ForeColorUnselected;
}
if (_theme == ThemeStyle.Light)
pictureBox.Image = ImageSelected;
else
pictureBox.Image = Image;
//labelName.ForeColor = Color.FromArgb(190, 192, 189);
}
#region CLICK & DOUBLE CLICK
public delegate void OnDoubleClickEvent();
public event OnDoubleClickEvent OnButtonDoubleClick;
public delegate void OnClickEvent();
public event OnClickEvent OnButtonClick;
private void OnObjClick(object sender, EventArgs e)
{
if (!_selected && _selectable)
{
//if (!_selectable)
{
IsSelected = true;
Selected();
if (OnButtonClick != null)
OnButtonClick();
}
this.OnClick(EventArgs.Empty);
}
if (!_selected && ! _selectable)
this.OnClick(EventArgs.Empty);
}
private void OnObjDoubleClick(object sender, EventArgs e)
{
if (_selected && _selectable)
{
if (OnButtonDoubleClick != null)
OnButtonDoubleClick();
this.OnDoubleClick(EventArgs.Empty);
}
if (_selected && !_selectable)
this.OnDoubleClick(EventArgs.Empty);
}
#endregion
private Color GetThemeBgColor(ThemeStyle theme, bool isSelected)
{
switch (_theme)
{
case ThemeStyle.Teal:
return (isSelected ? Color.FromArgb(31, 180, 174) : Color.FromArgb(11, 180, 174));
case ThemeStyle.Orange:
return (isSelected ? Color.FromArgb(239, 124, 0) : Color.FromArgb(239, 104, 0)); ;
case ThemeStyle.Bordo:
return (isSelected ? Color.FromArgb(196, 34, 47) : Color.FromArgb(176, 34, 47));
case ThemeStyle.Cofee:
return (isSelected ? Color.FromArgb(71, 58, 39) : Color.FromArgb(51, 58, 39));
case ThemeStyle.Aqua:
return (isSelected ? Color.FromArgb(61, 102, 205) : Color.FromArgb(61, 102, 181));
case ThemeStyle.Olive:
return (isSelected ? Color.FromArgb(141, 158, 0) : Color.FromArgb(141, 128, 0));
case ThemeStyle.DarkOrange:
return (isSelected ? Color.FromArgb(149, 74, 24) : Color.FromArgb(119, 74, 24));
case ThemeStyle.Blue:
return (isSelected ? Color.FromArgb(0, 22, 69) : Color.FromArgb(0, 72, 119));
case ThemeStyle.Light:
return (isSelected ? Color.FromArgb(233, 233, 233) : Color.FromArgb(255, 255, 255)); ;
default: return Color.Black;
}
}
private Color GetThemeBgIconColor(ThemeStyle theme, bool isSelected)
{
switch (_theme)
{
case ThemeStyle.Teal:
return (isSelected ? Color.FromArgb(31, 180, 174) : Color.FromArgb(11, 180, 174));
case ThemeStyle.Orange:
return (isSelected ? Color.FromArgb(239, 124, 0) : Color.FromArgb(239, 104, 0)); ;
case ThemeStyle.Bordo:
return (isSelected ? Color.FromArgb(196, 34, 47) : Color.FromArgb(176, 34, 47));
case ThemeStyle.Cofee:
return (isSelected ? Color.FromArgb(71, 58, 39) : Color.FromArgb(51, 58, 39));
case ThemeStyle.Aqua:
return (isSelected ? Color.FromArgb(61, 102, 205) : Color.FromArgb(61, 102, 181));
case ThemeStyle.Olive:
return (isSelected ? Color.FromArgb(141, 158, 0) : Color.FromArgb(141, 128, 0));
case ThemeStyle.DarkOrange:
return (isSelected ? Color.FromArgb(149, 74, 24) : Color.FromArgb(119, 74, 24));
case ThemeStyle.Blue:
return (isSelected ? Color.FromArgb(79, 139, 237) : Color.FromArgb(15, 115, 211));
case ThemeStyle.Light:
return (isSelected ? Color.FromArgb(222, 222, 222) : Color.FromArgb(255, 255, 255)); ;
default: return Color.Black;
}
}
private Color GetForeColor(ThemeStyle theme, bool isSelected)
{
switch (_theme)
{
case ThemeStyle.Teal:
return (isSelected ? Color.FromArgb(31, 180, 174) : Color.FromArgb(11, 180, 174));
case ThemeStyle.Orange:
return (isSelected ? Color.FromArgb(239, 124, 0) : Color.FromArgb(239, 104, 0)); ;
case ThemeStyle.Bordo:
return (isSelected ? Color.FromArgb(196, 34, 47) : Color.FromArgb(176, 34, 47));
case ThemeStyle.Cofee:
return (isSelected ? Color.FromArgb(71, 58, 39) : Color.FromArgb(51, 58, 39));
case ThemeStyle.Aqua:
return (isSelected ? Color.FromArgb(61, 102, 205) : Color.FromArgb(61, 102, 181));
case ThemeStyle.Olive:
return (isSelected ? Color.FromArgb(141, 158, 0) : Color.FromArgb(141, 128, 0));
case ThemeStyle.DarkOrange:
return (isSelected ? Color.FromArgb(149, 74, 24) : Color.FromArgb(119, 74, 24));
case ThemeStyle.Blue:
return (isSelected ? Color.FromArgb(79, 139, 237) : Color.FromArgb(162, 229, 255));
case ThemeStyle.Light:
return (isSelected ? Color.FromArgb(0, 0, 0) : Color.FromArgb(0, 0, 0)); ;
default: return Color.Black;
}
}
#region TOOLTIP MOUSE EVENTS
/// <summary>
/// Display the ToolTip as a result of the mouse entering this control
/// </summary>
private void Event_MouseEnter(object sender, EventArgs e)
{
DisplayToolTip(sender);
}
/// <summary>
/// Display the ToolTip as a result of the mouse hovering over this control
/// </summary>
private void Event_MouseHover(object sender, EventArgs e)
{
DisplayToolTip(sender);
}
/// <summary>
///
/// </summary>
private void Event_MouseLeave(object sender, EventArgs e)
{
if (sender is Panel)
toolTip.Hide((Panel)sender);
else if (sender is PictureBox)
toolTip.Hide((PictureBox)sender);
else if (sender is Label)
toolTip.Hide((Label)sender);
}
private void DisplayToolTip(object sender)
{
// display only if the title was set
if (_toolTip.Length > 0 && this.Size.Width < 80)
toolTip.Show(" " + _toolTip + " ", (Control)sender, 15000);
}
#endregion
}
}