본문 바로가기

C#.NET

MDI Form 생성하기

SDI (Single Document Interface) & MDI(Multiple Document Interface)

SDI는 Wordpad와 같이 하나의 창이 열리면 다른 창은 열리지 않는 방법의 Form이고,

MDI는 부모 Form 안에서 다시 자식 Form들을 생성하여 여러 Form에서 작업이 가능하도록 하는 방법이다.

 

일반 Form을 MDI Form으로 만드는 방법

  • Form 속성의 IsMdiContainer = Ture로 설정
  • WindowsState=Maximize로 하면 화면 전체 가득 찬 폼이 실행

     

 

 

  • 실습을 위해 아래와 같이 menu내용 기입.

     

  • 자식으로 생성될 Form 추가

     

  • StandardForm을 클릭하였을 때 발생할 이벤트 설정

private void standardedFormToolStripMenuItem_Click(object sender, EventArgs e)

{

//1.새로운 폼을 생성

Form standardform = new Form();

 

//2.새로운 폼에 타이틀 설정

standardform.Text = "표준 폼";

 

//3.새로운 폼이 누구의 자식인가 알리기

standardform.MdiParent = this;// 현재 form이 parent 임을 지정

 

//4.화면에 새로운 form 나타내기

standardform.Show();

 

}

 

  • Maximum Form 을 클릭하였을 때 발생할 이벤트 설정

private void maximunFormToolStripMenuItem_Click(object sender, EventArgs e)

{

 

//1.새로운 폼 생성

Form maxform = new Form();

 

//2.새로운 폼의 타이틀 설정

maxform.Text = "최대화된 폼";

 

//3.새로운 폼에 배경색 변경하기

maxform.BackColor = System.Drawing.Color.Blue;

 

//4.새로운 폼의 최대화하기

maxform.WindowState = System.Windows.Forms.FormWindowState.Maximized;

 

//5. 누구의 자식인지 알리기

maxform.MdiParent = this;

 

//6. 화면에 출력

maxform.Show();

 

}

 

  • bottenOfCreatedForm을 클릭하였을 때 발생할 이벤트 설정

private void bottenOfCreatedFormToolStripMenuItem_Click(object sender, EventArgs e)

{

Form newform = new Form();

 

newform.Text = "버튼이 존재하는 폼";

 

newform.BackColor = System.Drawing.Color.Yellow;

 

//새로운 버튼 생성

Button newstandardbutton = new Button();

 

//버튼의 Width 설정

newstandardbutton.Width = 120;

 

//버튼의 Text 설정

newstandardbutton.Text = "새로운 표준 폼";

 

//버튼의 위치 설정

newstandardbutton.Left = (newform.Width - newstandardbutton.Width) / 2;

 

//Control의 위쪽 가장자리와 해당 컨테이너 Client 영역 사이의 거리

newstandardbutton.Top = 20;

 

//버튼을 클릭하면 새로운 폼 생성

newstandardbutton.Click += new System.EventHandler(this.bottenOfCreatedFormToolStripMenuItem_Click);

 

//Form에 버튼 추가

newform.Controls.Add(newstandardbutton);

 

//새로운 폼이 누구의 폼인지 알리기

newform.MdiParent=this;

 

//보여주기

newform.Show();

 

}

 

'C#.NET' 카테고리의 다른 글

NotifyIcon  (0) 2009.05.08
트리뷰(TreeView)  (0) 2009.05.07
List View  (0) 2009.05.07
DateTimePicker_Control  (0) 2009.05.06
Progress Bar  (0) 2009.05.06
Windows Form - 5월6일  (1) 2009.05.06
소설 같은 C# Chapter 3  (0) 2009.04.30
0428 C# (초급)실습예제들  (0) 2009.04.28
Chapter02 C# Language  (0) 2009.04.28
0427_C# 간단한 실습  (0) 2009.04.27