125. 키보드(Keyboard) 이벤트 실습
.NET프로그래밍/WinForm 2009. 9. 2. 09:25 |
==> Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace MyWinForms
{
static class Program
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Sample.FrmKeyboard());
}
}
}
==============================================================================================
==> FrmKeyboard.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyWinForms.Sample
{
public partial class FrmKeyboard : Form
{
public FrmKeyboard()
{
InitializeComponent();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// 엔터키를 타이핑했을 때 다음 텍스트박스로 이동
if (e.KeyChar == (char)Keys.Enter)
{
textBox2.Focus();
}
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
// 엔터키 입력시 확인 버튼으로 포커스
if (e.KeyCode == Keys.Enter)
{
button1.Focus();
}
}
}
}
< 실행결과 >
--> '국어'점수의 "TextBox"에 텍스트(100) 입력 후, 엔터키를 타이핑했을 때 다음 텍스트박스로 이동
--> '영어'점수의 "TextBox"에 텍스트(90) 입력 후, 엔터키 입력시 "확인" 버튼으로 포커스() 맞춰짐.
'.NET프로그래밍 > WinForm' 카테고리의 다른 글
127. 마우스다운(MouseDown) / 마우스무브(MouseMove) 이벤트(= 마우스드래그하여 선그리기) (0) | 2009.09.02 |
---|---|
126. KeyDown이벤트를 이용하여 원 그리기 (0) | 2009.09.02 |
119. 초간단 메모장에서 "인쇄 미리 보기" 기능 구현하기 (0) | 2009.08.31 |
118. 초간단 메모장에 파일드롭(Drag & Drop) 기능 추가하기 (0) | 2009.08.31 |
117. 초간단 메모장에 복사(Copy) / 붙여넣기(Paste) 기능 추가하기 (0) | 2009.08.31 |