using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace buttonmake
{
public partial class Form1 : Form
{
public int puzX; //버튼의 가로 갯수
public int puzy; //버튼의 세로 갯수
public int puzmax; //버튼의 전체 갯수
public int puzFormSize = 35; //버튼의 크기
Button[] Bpuzz; //버튼형 배열 선언....
public Form1()
{
InitializeComponent();
}
private void formInitialize()
{
int count=0; //버튼에 먹여줄 인덱스
this.Size = new Size(puzX * puzFormSize + 30, puzy * puzFormSize + 80);
//폼 사이즈(유동적임)
Bpuzz = new Button[puzmax];
//버튼형 배열 생성
for (int i = 0; i < puzmax; i++)
Bpuzz[i] = new Button(); //초기화
for (int i = 0; i < puzy;i++) //가로만큼...
{
for (int j = 0; j < puzX;j++) //세로만큼...
{
Bpuzz[count].Width = puzFormSize; //버튼의 가로 크기
Bpuzz[count].Height = puzFormSize; //버튼의 세로 크기
Bpuzz[count].Top = i * puzFormSize + 40; //top
Bpuzz[count].Left = j * puzFormSize + 10; //left
Bpuzz[count].Font = new System.Drawing.Font("굴림", 8f); //font
Bpuzz[count].Click += new EventHandler(buttonClick); //이벤트 등록
Bpuzz[count].Text = (count + 1).ToString();
this.Controls.Add(Bpuzz[count]);
count++;
}
}
}
private void buttonClick(object sender, EventArgs e)
{
myButton btn = (myButton)sender;
btn.BackColor = Color.Blue;
MessageBox.Show(btn.Text.ToString());
}
private void btn_make_Click(object sender, EventArgs e)
{
puzX = int.Parse(num가로.Value.ToString());
puzy = int.Parse(num세로.Value.ToString());
puzmax = puzX * puzy;
formInitialize();
}
}
}
'C#' 카테고리의 다른 글
C# 에서 Char[] 배열에 포함된 데이타를 string으로 (0) | 2010.01.03 |
---|---|
퍼즐 (0) | 2010.01.03 |