picture 박스보다 큰 이미지를 Picture 박스에 이미지를 불러온뒤 움직이기
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 MoveImageOnPictrueBox
{
public partial class Form1 : Form
{
private bool IsClicked = false;
private Bitmap bm;
private Point recLoc;
private Point choosingPoint;
public Form1()
{
InitializeComponent();
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
bm = new Bitmap(openFileDialog1.FileName);
pictureBox1.Image = bm;
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.InitialDirectory = Application.StartupPath;
openFileDialog1.ShowDialog();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if(pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (IsClicked)
{
e.Graphics.Clear(Color.White);
e.Graphics.DrawImage(bm, recLoc);
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
IsClicked = true;
choosingPoint.X = e.X;
choosingPoint.Y = e.Y;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (IsClicked)
{
recLoc.X = recLoc.X + e.X - choosingPoint.X;
recLoc.Y = recLoc.Y + e.Y - choosingPoint.Y;
choosingPoint = e.Location;
pictureBox1.Invalidate();
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
IsClicked = false;
}
}
}
'개발 > C#' 카테고리의 다른 글
Dialog Boxes In C# (0) | 2018.03.20 |
---|---|
[DataGirdview] 더블 버퍼링 (0) | 2018.02.23 |
[이미지] C# Picture 박스에서 다른 Picture 박스로 이미지 끌어다 놓기 (0) | 2018.02.13 |
[이미지] C# 불러온 이미지 위치 조정후 저장하기 (0) | 2018.02.07 |
[이미지] C# 이미지위에 다른이미지 올려 마우스로 이동하기 (0) | 2018.02.07 |
[이미지] C# PictureBox 움직이기 (0) | 2018.02.07 |
[이미지] C# 이미지 회전 (0) | 2018.02.07 |
[이미지] C# 이미지 끌어다 놓기(Drag and Drop) (0) | 2018.02.07 |