C#용 kButton 클래스와 사용법
----------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
enum kButtonStyle
{
kb00Hori = 0,
kb01Vert
};
class kButton
{
// 남은 일 - 캡션 위치를 잡아주기
private Color col1 = Color.FromArgb(0, 251, 0);
private Color col0 = Color.Gray;
private Button button;
private PictureBox picbox;
private kButtonStyle kbuttonstyle;
private int LampHOffset = 7;
private int LampVOffset = 1;
private double LampSizeRatio = 0.7;
private int LampThickness = 10;
public bool Checked = false;
public kButton(kButtonStyle style, Button btn, int lamphoffset,
int lampvoffset, double sizeratio, int lampthickness)
{
button = btn;
picbox = new PictureBox();
{
picbox.BorderStyle = BorderStyle.Fixed3D;
btn.Parent.Controls.Add(picbox);
this.picbox.Click += new System.EventHandler(this.picbox_Click);
}
kbuttonstyle = style;
LampHOffset = lamphoffset;
LampVOffset = lampvoffset;
LampSizeRatio = sizeratio;
LampThickness = lampthickness;
DispStatus();
}
private void picbox_Click(object sender, EventArgs e)
{
button.PerformClick();
}
public void Invert()
{
Checked = !Checked;
DispStatus();
}
public void DispStatus()
{
picbox.BackColor = Checked ? col1 : col0;
if (kbuttonstyle == kButtonStyle.kb00Hori)
{
picbox.Width = LampThickness;
picbox.Height = Convert.ToInt32(button.Height * LampSizeRatio);
picbox.Left = button.Left + LampHOffset;
picbox.Top = button.Top + (button.Height - picbox.Height) / 2 + LampVOffset;
picbox.BringToFront();
}
else if (kbuttonstyle == kButtonStyle.kb01Vert)
{
picbox.Width = Convert.ToInt32(button.Width * LampSizeRatio);
picbox.Height = LampThickness;
picbox.Left = button.Left + (button.Width - picbox.Width) / 2 + LampVOffset;
picbox.Top = button.Top + button.Height - LampHOffset - LampThickness;
picbox.BringToFront();
}
else
{ }
}
}
----------------------------------------------------------------------------------------------
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
kButton ktn1;
kButton ktn2;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ktn1 = new kButton(kButtonStyle.kb00Hori, btnA, 7, 1, 0.7, 10);
ktn2 = new kButton(kButtonStyle.kb01Vert, btnB, 5, 0, 0.8, 8);
}
private void btnA_Click(object sender, EventArgs e)
{
bool changed_state = !ktn1.Checked;
// do something
ktn1.Invert();
}
private void btnB_Click(object sender, EventArgs e)
{
bool changed_state = !ktn1.Checked;
// do something
ktn2.Invert();
}
}
}