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 WindowsForms01
{
public partial class Key01 : Form
{
//키(키보드) 관련 이벤트
//1. KeyDown : 키를 눌렀을때
// - 물리적인 키에 반응하는 이벤트
// - A키 다운 -> a? A? ㅁ? 구분X
// - 키보드에 있는 모든 키에 반응(***);
//2. KeyUp : 키를 뗏을떄
// - KeyDown의 반대
//3. KeyPress : 키를 눌렀을때
// - 문자키에 반응하는 이벤트
// - 방향키, 펑션키, Ctrl, Shift등.. 반응X
// - A키 다운 -> a? A? 구분O
public Key01()
{
InitializeComponent();
}
private void Key01_Load(object
sender, EventArgs e)
{
}
private void Key01_KeyDown(object
sender, KeyEventArgs e)
{
//폼에 포커스가 있을때 키를 누르면 발생
//this.Text =
DateTime.Now.ToString();
//뭘? e.KeyCode
//this.Text =
e.KeyCode.ToString();
//if (e.KeyCode ==
Keys.F1)
//{
// MessageBox.Show("확인");
//}
//위치 x값 y값
M1(e);
M2(e);
}
private void M2(KeyEventArgs e)
{
Size now = this.Size;
Size move = now;
if (e.KeyCode ==
Keys.Up)
move = new
Size(now.Width, now.Height - 10);
else if (e.KeyCode == Keys.Down)
move = new
Size(now.Width, now.Height + 10);
else if (e.KeyCode == Keys.Left)
move = new
Size(now.Width - 10, now.Height);
else if (e.KeyCode == Keys.Right)
move = new
Size(now.Width + 10, now.Height);
this.Size = move;
}
private void M1(KeyEventArgs e)
{
Point now = this.Location;
Point move = now;
if (e.KeyCode ==
Keys.Up)
move = new
Point(now.X, now.Y - 10);
else if (e.KeyCode == Keys.Down)
move = new
Point(now.X, now.Y + 10);
else if (e.KeyCode == Keys.Left)
move = new
Point(now.X - 10, now.Y);
else if (e.KeyCode == Keys.Right)
move = new
Point(now.X + 10, now.Y);
this.Location =
move;
}
}
}
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 WindowsForms01
{
public partial class Mouse01 : Form
{
public Mouse01()
{
InitializeComponent();
}
private void Mouse01_MouseDown(object
sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Graphics
g = this.CreateGraphics();
Brush
brush = new SolidBrush(Color.Red);
string txt
= string.Format("{2}클릭 : {0}, {1}", e.X, e.Y, e.Button);
g.DrawString(txt, this.Font,
brush, e.X, e.Y);
}
}
private void Mouse01_MouseUp(object
sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Graphics
g = this.CreateGraphics();
Brush
brush = new SolidBrush(Color.Blue);
string txt
= string.Format("{2}클릭 : {0}, {1}", e.X, e.Y, e.Button);
g.DrawString(txt, this.Font,
brush, e.X, e.Y);
}
else if(e.Button == MouseButtons.Middle)
{
//특정 객체의 무효화 영역을 강제로 발생
this.Invalidate();
}
}
}
}
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 WindowsForms01
{
public partial class Mouse02 : Form
{
public Mouse02()
{
InitializeComponent();
}
private void Mouse02_MouseLeave(object
sender, EventArgs e)
{
//포인터가 나갔을떄
this.BackColor = SystemColors.Control;
}
private void Mouse02_MouseMove(object
sender, MouseEventArgs e)
{
//해당 객체영역내에서 포인터가 이동할때마다..
this.Text = string.Format("{0},
{1}", e.X, e.Y);
this.button1.Location
= new Point(e.X
+ 5, e.Y + 5);
}
private void Mouse02_MouseEnter_1(object
sender, EventArgs e)
{
//포인터가 들어왔을떄
this.BackColor = Color.Yellow;
}
}
}
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsForms01 { public partial class Mouse03 : Form { private Point p; private Point temp; public Mouse03() { InitializeComponent(); p = new Point(0, 0); temp = new Point(0, 0); } private void Mouse03_MouseMove(object
sender, MouseEventArgs e) { Graphics g = this.CreateGraphics(); Pen pen = new Pen(Color.Black); Pen temppen = new Pen(SystemColors.Control); //직선 //g.DrawLine(pen, 10,
10, 100, 300); g.DrawLine(temppen, p, temp); g.DrawLine(pen, p, e.Location); temp = e.Location;//포인터의 마지막 위치 } } } 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 WindowsForms01 { public partial class Mouse04 : Form { private Point p; private bool isLeft;//true : 마우스눌려진, false : 마우스뗀상태 public Mouse04() { InitializeComponent(); p = new Point(0, 0); isLeft = false; } private void Mouse04_MouseMove(object
sender, MouseEventArgs e) { //마우스 왼쪽 버튼이 눌렸을때만.. if (isLeft) { Point
now = e.Location;//현재위치 Graphics
g = this.CreateGraphics(); Pen pen
= new Pen(Color.Black); g.DrawLine(pen, p, now);//마우스 포인터 이동 이후 p = now;//마우스 포인터 이동 이전 } } private void Mouse04_MouseDown(object
sender, MouseEventArgs e) { this.isLeft = true; p = e.Location;//마우스버튼을 누른곳에서 부터 선을 그리기 시작 } private void Mouse04_MouseUp(object
sender, MouseEventArgs e) { this.isLeft = false; } } }
using System;