[C#기초] 8. 윈도우 프로그래밍 및 이벤트 핸들러

INDEX

  1. 윈도우 폼
  2. 간단한 이벤트 핸들러 및 출력

윈도우 폼

Program.cs

Form.cs

Form.Designer.cs

From 속성

메서드

간단한 이벤트 핸들러 및 출력

간단한 이벤트 핸들러 생성 (Visual studio 2017 기준)

화면 출력 객체 가져오기

간단한 출력

  1. GUI를 이용하여 Form.cs에서 이벤트-모양-Paint를 클릭

  2. From.Designer.cs파일에서 아래 추가

    this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    
  3. Form.cs파일에서 아래 추가

    private void Form1_Paint(object sender, PaintEventArgs e) {  }
    

간단한 출력 예제 코드

private void Form1_Paint(object sender, PaintEventArgs e) 
{
    e.Graphics.DrawString("Hello World!", Font, Brushes.Black, 10, 10);
    e.Graphics.DrawLine(Pens.Red,10,10,200,10);
    e.Graphics.DrawLine(Pens.Black,10,20,100,100);
    e.Graphics.DrawLine(Pens.Black,130,20,100,100);
}