window from 다루기
designer.cs 에서 만들어둔 기능 코드로 확인 가능
윈도우 폼에서 메서드 활용하기
이벤트 활용
cf) 이벤트를 여러가지 이름으로 부른다 이벤트 = 인터럽트= 메세지
이벤트를 선택해서 더블클릭하면
event handler 가 생성 된다.
this.button1.Click += new System.EventHandler(this.button1_Click);
private void button1_Click(object sender, EventArgs e)// fallback 함수
{
textBox1.Text += "버튼 눌림";
label1.Text += "버튼 눌림";
}
timer 기능 설정
간단한 시간 타이며 생성
private void timer1_Tick(object sender, EventArgs e)
시간 간격으로 호출해준다.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _210602_005
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
textBox1.Text = "00:00:00";
}
private int iNum = 0;
private void timer1_Tick(object sender, EventArgs e)
{
//textBox1.Text = iNUm.ToString();
textBox1.Text = string.Format("{0,2:00}:{1,2:00}:{2,2:00}", (iNum / 3600), (iNum / 60) % 60, iNum % 60);
++iNum;
//@"{00:00:00:00}",
}
private void button1_Click(object sender, EventArgs e)
{
if(timer1.Enabled)
{
timer1.Enabled = false;
button1.Text = "시작";
}
else
{
timer1.Enabled = true;
button1.Text = "중지";
}
}
private void button2_Click(object sender, EventArgs e)
{
iNum = 0;
textBox1.Text = string.Format("{0,2:00}:{1,2:00}:{2,2:00}", (iNum / 3600), (iNum / 60) % 60, iNum % 60);
}
}
}
결과
messagebox
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _210602_006
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// control class 가 button class 의 상위 클래스임으로 add 에 매개변수로 쓰일 수 있다.
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult Temp = MessageBox.Show("이거슨 내용이다.","여기는 제목이다",MessageBoxButtons.YesNo);
if(Temp == DialogResult.Yes)
{
button1.Text = "예 눌렀음";
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult Temp = MessageBox.Show("종료 전 저장 할까요?", "저장 하시겠습니까?", MessageBoxButtons.YesNo);
if (Temp == DialogResult.Yes)
{
MessageBox.Show("저장완료.");
}
else
{
MessageBox.Show("저장하지 않고 종료 합니다. .");
}
}
}
}
MDI : 화면안에 또 다른 화면을 보여줌
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _210602_007
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
IsMdiContainer = true;
}
private void button1_Click(object sender, EventArgs e)
{
Smart aSmart = new Smart();
aSmart.MdiParent = this;
aSmart.Show();
}
class Smart : Form
{
public Smart()
{
Text = "스마트 클래스의 폼 창 만들기";
}
}
}
}
mdi 로 만든 화면
Modal 창
: 커져있는 창만 선택 가능
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace _210602_007
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Smart aSmart = new Smart();
aSmart.ShowDialog();
}
class Smart : Form
{
public Smart()
{
Text = "스마트 클래스의 폼 창 만들기";
}
}
}
}
댓글