I have a form with 6 labels 4 of them have png Images in them. I have it set up so the user can drag one of the 4 images into label5 and label6 would give them a message to tell them which of the 4 they picked
I have the drag drop part working but cannot figure out what code I need to tell them which was picked.
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;
using System.IO;
namespace Drag_Drop_Tester2
{
public partial class Form1 : Form
{
Image img1 = Image.FromFile("Peg_Red.png");
Image img2 = Image.FromFile("Peg_Blue.png");
Image img3 = Image.FromFile("Peg_Green.png");
Image img4 = Image.FromFile("Peg_Orange.png");
public Form1()
{
InitializeComponent();
}
private void DD_MouseDown(object sender, MouseEventArgs e)
{
Label lblPic = (Label)sender;
lblPic.DoDragDrop(lblPic.Image, DragDropEffects.Copy);
}
private void DD_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Bitmap)))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void DD_DragDrop(object sender, DragEventArgs e)
{
Label lblPic = (Label)sender;
Graphics g = lblPic.CreateGraphics();
g.DrawImage((Image)e.Data.GetData(typeof(Bitmap)), new Point(0, 0));
if ("code that goes here")
lblMsg.Text = "You picked red";
else
lblMsg.Text = "I can't decide what you picked";
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…