SafeDispatch/SDRgateway/MenuButton.cs

112 lines
2.8 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 SDRgateway
{
public partial class MenuButton : UserControl
{
public enum ThemeStyle { Teal, Read };
[Description("Title"), Category("Data")]
public string Title
{
get { return labelName.Text; }
set { labelName.Text = value; }
}
[Description("Image"), Category("Data")]
public Image Image
{
get { return pictureBox.Image; }
set { pictureBox.Image = value; }
}
[Description("Theme"), Category("Data")]
private ThemeStyle _theme;
public ThemeStyle Theme
{
get { return _theme; }
set { _theme = value; }
}
[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();
}
}
public MenuButton()
{
InitializeComponent();
//UnSelected();
}
public void Selected()
{
panelBack.BackColor = Color.FromArgb(31, 180, 174);
this.BackColor = Color.FromArgb(31, 180, 174);
labelName.ForeColor = Color.Black;
if(OnButtonClick != null)
OnButtonClick();
}
public void UnSelected()
{
panelBack.BackColor = Color.Transparent;
this.BackColor = Color.Transparent;
labelName.ForeColor = Color.FromArgb(190, 192, 189);
}
public delegate void OnClickEvent();
public event OnClickEvent OnButtonClick;
private void OnObjClick(object sender, EventArgs e)
{
if (!_selected && _selectable)
{
//if (!_selectable)
{
IsSelected = true;
Selected();
}
this.OnClick(EventArgs.Empty);
}
if (!_selected)
this.OnClick(EventArgs.Empty);
}
}
}