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 ryControls { /// /// /// [DefaultEvent("Click")] public partial class PicButton : UserControl { private bool Mouse_Enter = false; /// /// /// public PicButton() { InitializeComponent(); SetEvent(this); SetEvent(pictureBox1); SetEvent(label1); SetEvent(zhLoading1); void SetEvent(Control ct) { ct.Click+= Button_Click; ct.MouseDown += Ct_MouseDown; ct.MouseEnter += Button_MouseEnter; ct.MouseLeave += Button_MouseLeave; ct.MouseMove += Button_MouseMove; } } private void Ct_MouseDown(object sender, MouseEventArgs e) { if (!(sender is UserControl)) { base.OnMouseDown(e); } } private void Button_MouseMove(object sender, MouseEventArgs e) { if (!Mouse_Enter) { Mouse_Enter = true; zhLoading1.Location = new Point(0, 0); zhLoading1.Size = new Size(this.Width, this.Height); zhLoading1.ShowLoad(); } } private void Button_MouseEnter(object sender, EventArgs e) { //if (this.Bounds.Contains(MousePosition.X, MousePosition.Y); { zhLoading1.Location = new Point(0, 0); zhLoading1.Size = new Size(this.Width, this.Height); zhLoading1.ShowLoad(); } } private void Button_MouseLeave(object sender, EventArgs e) { switch (sender) { case ryControls.ZhLoading k: if (Mouse_Enter) { Mouse_Enter = false; zhLoading1.HideLoad(); } break; } } private void Button_Click(object sender, EventArgs e) { if (!(sender is UserControl)) { base.OnClick(e); } Selected = !Selected; } /// /// 图标 /// public Image Image { get { return pictureBox1.Image; } set { pictureBox1.Image = value; } } /// /// 标题 /// public string Title { get { return label1.Text; } set { label1.Text = value; } } private string _ToolTip = ""; /// /// 悬浮提示 /// public string ToolTip { get { return _ToolTip; } set { _ToolTip = value; toolTip1.SetToolTip(pictureBox1, value); toolTip1.SetToolTip(this, value); toolTip1.SetToolTip(label1, value); toolTip1.SetToolTip(zhLoading1, value); } } /// /// 标题颜色 /// public Color TitleColor { get { return label1.ForeColor; } set { label1.ForeColor = value; } } /// /// 设置按钮 /// /// /// public void SetButton(string title,Image img) { Title = title; Image = img; } private bool _selected = false; /// /// 判断和设置是否选择 /// public bool Selected { get { return _selected; } set { if (_selected != value) { _selected = value; if (_selected) { zhLoading1.Location = new Point(0, 0); zhLoading1.Size = new Size(this.Width, this.Height); zhLoading1.ShowLoad(); } else { zhLoading1.HideLoad(); } } } } } }