반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
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 WindowsFormsApp3 { public partial class Form1 : Form { private Point startPoint = Point.Empty; private Point movePoint = Point.Empty; bool isClick = false; public Form1() { InitializeComponent(); } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isClick = true; this.startPoint = new Point(e.Location.X - movePoint.X, e.Location.Y - movePoint.Y); } } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (isClick) { this.movePoint = new Point(e.Location.X - startPoint.X, e.Location.Y - startPoint.Y); this.pictureBox1.Invalidate(); } } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (isClick) isClick = false; } private void pictureBox1_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(Color.White); if (this.pictureBox1.Image != null) e.Graphics.DrawImage(this.pictureBox1.Image, movePoint); } } } |
실행화면
'프로그래밍 > C#' 카테고리의 다른 글
[C#]폼 중복 실행 방지 (0) | 2017.05.03 |
---|---|
[C#]드래그앤드롭 (0) | 2017.05.01 |
[C#] 화면스크린 갭쳐 (0) | 2017.04.25 |
[C#]소켓으로 이미지 전송하기 (2) | 2017.04.23 |
[C#]as is (0) | 2017.04.22 |