Saumya Singh

Saumya Singh

  • NA
  • 11
  • 693

wpf Application

Dec 17 2015 6:05 AM
Hello,
I am developing one small application in that i want to drag one button1 and drop into button2
but my problem is button2 should not accept any other button apart from button1.
I am new to this .
Here is my code: 
 
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 DragDrop
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const byte CtrlMask = 8;
private void sourceButton_MouseDown(object sender, MouseEventArgs e)
{
// sourceButton.DoDragDrop(sourceButton.Text, DragDropEffects.Copy);
if (e.Button == MouseButtons.Left)
{
sourceButton.Select();
sourceButton.DoDragDrop(sourceButton.Text, DragDropEffects.Move | DragDropEffects.Copy);
}
}
private void targetButton_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
if ((e.KeyState & CtrlMask) == CtrlMask)
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.Move;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void targetButton_DragDrop(object sender, DragEventArgs e)
{
Button btn = sender as Button;
if (btn == targetButton )
{
targetButton.Text = e.Data.GetData(DataFormats.Text).ToString();
}
else
{
}
}
private void sourceButton1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
sourceButton1.Select();
sourceButton1.DoDragDrop(sourceButton1.Text, DragDropEffects.Move | DragDropEffects.Copy);
}
}
private void targetButton1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
if ((e.KeyState & CtrlMask) == CtrlMask)
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.Move;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void targetButton1_DragDrop(object sender, DragEventArgs e)
{
Button btn = sender as Button;
if (btn == targetButton1 )
{
targetButton1.Text = e.Data.GetData(DataFormats.Text).ToString();
}
else
{
}
}
}
}

Answers (2)