254 lines
7.4 KiB
C#
254 lines
7.4 KiB
C#
//
|
|
// Copyright © 2006-2010, Intel Corporation. All rights reserved.
|
|
//
|
|
//File: AMT_CheckedButton.cs
|
|
//
|
|
// Contents: Defintion of logic of button (GUI componet)
|
|
//
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Drawing;
|
|
|
|
namespace AMT_SW_GUI
|
|
{
|
|
public partial class AMT_CheckedButton : Button
|
|
|
|
{
|
|
private bool _checked =false;
|
|
bool enabled = true;
|
|
//bool wide = false;
|
|
public AMT_CheckedButton()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public AMT_CheckedButton(IContainer container)
|
|
{
|
|
container.Add(this);
|
|
|
|
InitializeComponent();
|
|
AMT_CheckedButton_EnabledChanged(null, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnTextChanged(EventArgs e)
|
|
{
|
|
base.OnTextChanged(e);
|
|
AMT_CheckedButton_MouseLeave(null, null);
|
|
}
|
|
|
|
|
|
private void AMT_CheckedButton_EnabledChanged(object sender, EventArgs e)
|
|
{
|
|
if (this.Enabled)
|
|
AMT_CheckedButton_MouseLeave(sender, e);
|
|
else
|
|
this.BackgroundImage = Properties.Resources.large_disabled24;
|
|
|
|
if (this.Enabled)
|
|
this.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(59)))), ((int)(((byte)(108)))));
|
|
else
|
|
this.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(158)))), ((int)(((byte)(158)))), ((int)(((byte)(158)))));
|
|
|
|
}
|
|
|
|
protected override bool ShowFocusCues
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
public new bool Enabled
|
|
{
|
|
get { return enabled; }
|
|
set
|
|
{
|
|
base.Enabled = true;
|
|
bool difference = (enabled != value);
|
|
enabled = value;
|
|
if (difference)
|
|
AMT_CheckedButton_EnabledChanged(null, null);
|
|
}
|
|
}
|
|
|
|
|
|
/////// <summary>This feature can cause the button to dynamically become a wide button.</summary>
|
|
////[Description("This feature can cause the button to dynamically become a wide button. Important for localization")]
|
|
|
|
////public bool CanBeWide
|
|
////{
|
|
//// get { return wide; }
|
|
//// set { wide = value; if (wide) this.BackgroundImage = Properties.Resources.W_thin_normal; }
|
|
////}
|
|
|
|
|
|
protected override void OnClick(EventArgs e)
|
|
{
|
|
if (Enabled)
|
|
base.OnClick(e);
|
|
}
|
|
private void AMT_CheckedButton_Enter(object sender, EventArgs e)
|
|
{
|
|
if (this.Enabled)
|
|
{
|
|
if (Checked)
|
|
this.BackgroundImage = Properties.Resources.checked_btn_focused;
|
|
else
|
|
this.BackgroundImage = Properties.Resources.large_focus_normal24;
|
|
}
|
|
}
|
|
|
|
private void AMT_CheckedButton_Leave(object sender, EventArgs e)
|
|
{
|
|
if (this.Enabled)
|
|
{
|
|
if (Checked)
|
|
this.BackgroundImage = Properties.Resources.checked_btn;
|
|
else
|
|
this.BackgroundImage = Properties.Resources.large_normal24;
|
|
}
|
|
}
|
|
|
|
private void AMT_CheckedButton_TextChanged(object sender, EventArgs e)
|
|
{
|
|
AMT_CheckedButton_EnabledChanged(null, null);
|
|
}
|
|
|
|
public bool Checked {
|
|
get{return _checked;}
|
|
set{
|
|
if(value!= _checked){
|
|
_checked = value;
|
|
AMT_CheckedButton_MouseLeave(null, null);
|
|
this.Refresh();
|
|
}
|
|
} }
|
|
|
|
|
|
private void AMT_CheckedButton_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (this.Enabled)
|
|
{
|
|
if (Checked)
|
|
{
|
|
this.BackgroundImage = Properties.Resources.checked_btn_pressed;
|
|
}
|
|
else
|
|
{
|
|
this.BackgroundImage = Properties.Resources.large_pressed24;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void AMT_CheckedButton_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
|
|
if (this.Enabled)
|
|
{
|
|
if (this.Focused)
|
|
{
|
|
if (Checked)
|
|
this.BackgroundImage = Properties.Resources.checked_btn_focused;
|
|
else
|
|
this.BackgroundImage = Properties.Resources.large_focus_normal24;
|
|
}
|
|
else
|
|
{
|
|
if (Checked)
|
|
this.BackgroundImage = Properties.Resources.checked_btn;
|
|
else
|
|
this.BackgroundImage = Properties.Resources.large_normal24;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private void AMT_CheckedButton_MouseLeave(object sender, EventArgs e)
|
|
{
|
|
if (this.Enabled)
|
|
{
|
|
if (this.Focused)
|
|
if (Checked)
|
|
this.BackgroundImage = Properties.Resources.checked_btn_focused;
|
|
else
|
|
this.BackgroundImage = Properties.Resources.large_focus_normal24;
|
|
else
|
|
if (Checked)
|
|
this.BackgroundImage = Properties.Resources.checked_btn;
|
|
else
|
|
this.BackgroundImage = Properties.Resources.large_normal24;
|
|
}
|
|
}
|
|
|
|
|
|
private void AMT_CheckedButton_MouseEnter(object sender, EventArgs e)
|
|
{
|
|
if (this.Enabled)
|
|
{
|
|
if (this.Focused)
|
|
if (Checked)
|
|
this.BackgroundImage = Properties.Resources.checked_btn_focused_hover;
|
|
else
|
|
this.BackgroundImage = Properties.Resources.large_focus_normal24;
|
|
else
|
|
if (Checked)
|
|
this.BackgroundImage = Properties.Resources.checked_btn_hover;
|
|
else
|
|
this.BackgroundImage = Properties.Resources.large_over24;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
protected override void OnHelpRequested(HelpEventArgs hevent)
|
|
{
|
|
if (this.Enabled == true)
|
|
{
|
|
base.OnHelpRequested(hevent);
|
|
}
|
|
}
|
|
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
|
|
{
|
|
base.OnPaint(e);
|
|
if (!this.Text.EndsWith(" "))
|
|
{
|
|
this.Text += " ";
|
|
}
|
|
if (this.Checked)
|
|
{
|
|
int textWidth = (int)e.Graphics.MeasureString(this.Text, this.Font).Width;
|
|
int btnWidth = (int)this.Width;
|
|
|
|
// Create image.
|
|
Image checkedImage = Properties.Resources.check;
|
|
|
|
int X_location = this.Width - checkedImage.Width - 2;
|
|
// Create Point for upper-left corner of image.
|
|
Point ulCorner = new Point(X_location, 2);
|
|
|
|
// Draw image to screen.
|
|
e.Graphics.DrawImage(checkedImage, ulCorner);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|