티스토리 뷰
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 드래그드롭픽쳐
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox1_DragDrop(object sender, DragEventArgs e)
{
var data = e.Data.GetData(DataFormats.FileDrop);
if(data != null)
{
var fileNames = data as string[];
if (fileNames.Length > 0)
pictureBox1.Image = Image.FromFile(fileNames[0]);
}
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.AllowDrop = true;
pictureBox2.AllowDrop = true;
}
private void pictureBox1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void pictureBox2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Bitmap) && (e.AllowedEffect & DragDropEffects.Copy) != 0)
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void pictureBox2_DragDrop(object sender, DragEventArgs e)
{
pictureBox2.Image = (Bitmap)e.Data.GetData(DataFormats.Bitmap, true);
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.Copy);
}
}
}
}
'프로그래밍 > C#' 카테고리의 다른 글
C# 콘솔 테트리스 (0) | 2019.03.06 |
---|---|
c# QR코드 발생기 소스코드 (0) | 2019.03.04 |
C# 구구단 게임 만들기 (0) | 2019.02.28 |
C# 동적으로 텍스트박스, 라벨, 버튼 만들기 (0) | 2019.02.28 |
날짜조회하기 및 데이타그리드뷰에 mysql open하지 않고 뷰하기 (0) | 2019.01.23 |