Computers/Language 2012. 11. 11. 16:18


원저자

http://robotc.tistory.com/23


옮긴곳

http://yyman.tistory.com/207


Program.cs 에 다음과 같이 정의 한다.

 

static class Program

{

/// <summary>

/// 해당 응용 프로그램의 주 진입점입니다.

/// </summary>

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Form1());

Form2 fr = new Form2();

Application.Run(fr);

}

}

Program.cs에 녹색 부분에 있는 부분만 추가 하고 위 에

From1의 버튼 이벤트에 아까와 같은 코드를 그대로 쓰면

private void button1_Click(object sender, EventArgs e)

{

Form2 fr = new Form2();

    fr.Show();

this.Close();

}

이대로 쓰면 Form1 만 닫히고 Form2 이 열리는 것을 볼 수 있다.

static void Main() 에 미리 생성해 놓음 으로써 미리 프로그램이 시작할 때

메모리를 할당을 하고 Application.Run(fr); 함으로써 쓰레드를 생성해 주는 것이다.

즉 Form1 에서 Form2 fr = new Form2(); 을 프로그램 상에서 사용하게 되면 미리 할당한

Form2를 사용하게 되어 Form1이 닫혀도 Form2는 메모리를 유지되므로 닫히지 않는다.



posted by 털보네i
: