티스토리 뷰
콘솔 기본코드 : https://petra.tistory.com/1547
1
2
3
4
5
6
7 |
class Class1
{
public static void Main()
{
System.Windows.Forms.MessageBox.Show("Hello, world!");
}
} |
cs |
빈프로젝트 만들고 프로젝트에 클래스 파일 추가하고 위 코드를 입력한다.
윈도우 폼 프로그램이기 때문에 System, System.Drawing, System.Windows.Forms DLL 3개가 필요하다.
솔루션 탐색기에서 참조를 마우스 우측 버튼으로 클릭하여 참조추가를 선택한다.
아래 그림처럼 System을 체크표시하고 나머지 System.Drawing, System.Windows.Forms 3가지를 체크하여 추가해야한다.
실행화면>
1
2
3
4
5
6
7
8
9 |
class Class1
{
public static void Main()
{
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
form.Show();
System.Windows.Forms.Application.Run(); // 이 코드가 없으면 창이 나왔다가 바로 사라지면서 종료된다.
}
} |
cs |
실행결과>
위 실행 창에서 X 클릭해도 프로그램 종료가 되지 않고 코솔창을 닫아야만 종료가 되는 문제가 있다.
1
2
3
4
5
6
7
8
9 |
class Class1
{
public static void Main()
{
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
//form.Show();
System.Windows.Forms.Application.Run(form); // 이 코드가 없으면 창이 나왔다가 바로 사라지면서 종료된다.
}
} |
cs |
같은 코드인데 6행을 주석처리하고 form 을 Run()의 인수로 전달한다.
실행 결과는 위와 같지만, X 를 클릭하면 프로그램이 종료된다.
1
2
3
4
5
6
7
8
9
10 |
class Class1
{
public static void Main()
{
System.Windows.Forms.Form form = new System.Windows.Forms.Form();
System.Windows.Forms.Form form2 = new System.Windows.Forms.Form();
form2.Show();
System.Windows.Forms.Application.Run(form); // 이 코드가 없으면 창이 나왔다가 바로 사라지면서 종료된다.
}
} |
cs |
실행화면>