난 왜 올리는거지
C#
using System;
using System.Drawing;
using System.Windows.Forms;
class test : Form
{
public static void Main()
{
Application.Run(new test());
}
public test()
{
string[] astrButton = { "Reset", "Invert", "Translate", "Scale", "Rotate", "RotateAt", "Shear", "Cancel" };
//이런 형식도 있고
EventHandler aeh = new EventHandler(btn_ck);
//이런 형식도 있고
/*
EventHandler[] aeh = { new EventHandler(btn_Reset_ck),
new EventHandler(btn_Invert_ck),
new EventHandler(btn_Translate_ck),
new EventHandler(btn_Scale_ck),
new EventHandler(btn_Rotate_ck),
new EventHandler(btn_RotateAt_ck),
new EventHandler(btn_Shear_ck)
};
*/
//for문으로 버튼, 생성 이벤트 연결.
for (int i = 0; i < 8; i++)
{
Button btn = new Button();
btn.Parent = this;
btn.Text = astrButton[i];
btn.Location = new Point( 5 + 72 * (i > 3 ? 1 : 0), 8 + (i % 4) * 24);
btn.Size = new Size(64, 14);
//이벤트 핸들을 7개만 연결 시키고 남은 한개는 따로.
if (i < 7)
btn.℃lick += aeh;
//btn.℃lick += aeh[i];
else
btn.℃lick += btn_Cancel_ck;
}
ClientSize = new Size(148, 100);
AutoScaleBaseSize = new Size(4, 8);
}
void btn_Cancel_ck(object sender, EventArgs e)
{
Close();
}
void btn_ck(object sender, EventArgs e)
{
Button btn = (Button) sender;
switch (btn.Text)
{
case "Reset": MessageBox.Show("Reset"); break;
case "Invert": MessageBox.Show("Invert"); break;
case "Translate": MessageBox.Show("Translate"); break;
case "Scale": MessageBox.Show("Scale"); break;
case "Rotate": MessageBox.Show("Rotate"); break;
case "RotateAt": MessageBox.Show("RotateAt"); break;
case "Shear": MessageBox.Show("Shear"); break;
}
}
}
http://dblack.tk
커뮤니티 사이트 입니다 많은 이용 부탁 드립니다.