tbf/TBF/BenchControl/TestMethods/iPerlCommunication/CheckBoxImage.cs

46 lines
1.2 KiB
C#

///
/// Copyright (c) 2017 Sensus Metering Systems
///
using System;
using System.Drawing;
using System.Windows.Forms;
using TBF.Resources;
namespace TBF.BenchControl.TestMethods.iPerlCommunication
{
public class CheckBoxImage : PictureBox
{
private bool cbChecked;
private readonly Image checkedImg;
private readonly Image uncheckedImg;
public CheckBoxImage()
: this(new Bitmap(TBF.Properties.Resources.SwitchOn), new Bitmap(TBF.Properties.Resources.SwitchOff), true)
{
SizeMode = PictureBoxSizeMode.StretchImage;
}
public CheckBoxImage(Image checkedImg, Image uncheckedImg, bool initState)
: base()
{
this.checkedImg = checkedImg;
this.uncheckedImg = uncheckedImg;
Click += (sender, e) => { Checked = !Checked; };
Checked = initState;
}
public bool Checked
{
get { return cbChecked; }
set
{
if (Enabled)
{
Image = value ? checkedImg : uncheckedImg;
cbChecked = value;
}
}
}
}
}