I just threw this together.
Check the code - it's converted from VB.
(Try it using 2 of your top row buttons cut into approx. 100x35 pixels)
#region "Imports"using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms.Design;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.ComponentModel.Design;
#endregion
[ToolboxBitmap(typeof(Button)), ToolboxItem(true), DesignTimeVisible(true)]
public class OnOffButtons : System.Windows.Forms.Button
{
#region "Private members"
private Image m_OnImage = My.Resources.OnImage;
private Image m_OffImage = My.Resources.OffImage;
#endregion
private bool m_ON;
public OnOffButtons() : base()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
base.BackgroundImageLayout = ImageLayout.Zoom;
this.Text="";
SetImage();
}
public OnOffButtons(Image onImage, Image offImage) : base()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
base.BackgroundImageLayout = ImageLayout.Zoom;
m_OffImage = offImage;
m_OnImage = onImage;
this.Text="";
SetImage();
}
[RefreshProperties(RefreshProperties.Repaint)]
public Image OffImage {
get { return this.m_OffImage; }
set { this.m_OffImage = value; }
}
[RefreshProperties(RefreshProperties.Repaint)]
public Image OnImage {
get { return this.m_OnImage; }
set { this.m_OnImage = value; }
}
private void SetImage()
{
if (m_ON) {
this.BackgroundImage = m_OnImage;
} else {
this.BackgroundImage = m_OffImage;
}
Refresh();
}
protected override void OnClick(System.EventArgs e)
{
m_ON = !m_ON;
SetImage();
base.OnClick(e);
}
}