TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Saumya Singh
NA
11
701
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
{
}
}
}
}
Reply
Answers (
2
)
How to show image in rdlc report?
reload a form in initial state