Study - Programming/C#2007. 11. 26. 01:00

사용자 삽입 이미지


using System;
using System.Windows.Forms;

class MyClass : Form
{
    Button[] btn = new Button[4];
    Form[] newMDICHild = new Form[10];
    string[] strData = { "수평", "수직", "계단식", "아이콘" };

    public MyClass(string strText)
    {
        this.Text = strText;
        this.IsMdiContainer = true;
        this.Load += new EventHandler(this.Form_Load);
        this.Closed += new EventHandler(this.Form_Closed);

        for (int i = 0; i < 4; i++)
        {
            btn[i] = new Button();
            btn[i].Text = strData[i];
            btn[i].SetBounds(50 * i, 10, 50, 50);
            btn[i].Click += new EventHandler(this.Btn_Click);
            this.Controls.Add(btn[i]);
        }

        this.Show();
    }

    public static void Main(string[] args)
    {
        Application.Run(new MyClass("MDI"));
    }

    private void Form_Load(object sender, System.EventArgs e)
    {
        Console.WriteLine("윈도우에 자식창을 생성");
        Form[] newMDIChild = new Form[10];
        for(int i = 0 ;i < 10 ; i++)
        {
            newMDIChild[i] = new Form();
            newMDIChild[i].Text = i + "번째 자식창";
            newMDIChild[i].MdiParent=this;
            newMDIChild[i].Closed += new System.EventHandler(this.Form_Closed);

            newMDIChild[i].Show();
        }
    }
    private void Form_Closed(object sender, System.EventArgs e)
    {
        Console.WriteLine(((Form)sender).Text + "윈도우가 Closed됩니다.");
    }

    private void Btn_Click(object sender, System.EventArgs e)
    {
        if ((Button)sender == btn[0])
        {
            this.LayoutMdi(MdiLayout.TileHorizontal);
            this.Text = "수평 바둑판 정렬";
        }
        else if ((Button)sender == btn[1])
        {
            this.LayoutMdi(MdiLayout.TileVertical);
            this.Text = "수직 바둑판 정렬";
        }
        else if ((Button)sender == btn[2])
        {
            this.LayoutMdi(MdiLayout.Cascade);
            this.Text = "계단식 정렬";
        }
        else if ((Button)sender == btn[3])
        {
            this.LayoutMdi(MdiLayout.ArrangeIcons);
            this.Text = "아이콘 정렬";
        }
    }
}

  후.. 요즘 윈도우 프로그래밍에 맛들여서.. 이런거 공부해 보는게 마냥 재미있네. 어쨋든 슬럼프였는데 갈길을 찾아서 다행이다. 시험 기간 제대로 돌입하기전에는 열심히 해봐야지.

  C#문법을 조금만 아는 사람이라면 금방 파악할 수 있을 것이다. 그만큼 쉽고 편리하게 구현하는게 가능하다. 실제 윈폼 구현은 다 IDE를 이용해서 하지만 콘솔로도 이렇게 간단하게 할 수가 있다. 특히 이벤트 구현을 저렇게 쉽게 해줄 수 있다니.. MFC/API를 사용할때와 비교해서 이렇게 차이가 난다. VB를 해보았다면 그때의 기억을 살리면서 신나게 해볼 수 있을 것이다. 아 앞으로 배울 것들이 엄청 기대된다.

Posted by 머리