473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Drag and Drop

Hello, Newsgroupians:

I've been looking on the Internet for some resources to create a simple
drag-and-drop application, but they all seem too complicated or not what I
need.

I have created a Form with a ToolStrip that has a couple of buttons at the
top. What I want to do is allow the user to drag one of the button's from
the toolstrip to the client area. Once the user let's go, I want to create a
button in the client area at that point. This mimics Visual Studio when
visually creating Forms. Does anyone have any short code or resources that
could allow me to do this?

Thank you.
Trecius
Nov 5 '07 #1
2 4944
On Nov 5, 11:19 am, Trecius <Trec...@discussions.microsoft.comwrote:
Hello, Newsgroupians:

I've been looking on the Internet for some resources to create a simple
drag-and-drop application, but they all seem too complicated or not what I
need.

I have created a Form with a ToolStrip that has a couple of buttons at the
top. What I want to do is allow the user to drag one of the button's from
the toolstrip to the client area. Once the user let's go, I want to create a
button in the client area at that point. This mimics Visual Studio when
visually creating Forms. Does anyone have any short code or resources that
could allow me to do this?

Thank you.

Trecius
Someone else might be able to come up with something more graceful but
I would just do it all manually.

OnMouseDown = set bMoving = true;
OnMouseMove = if (bMoving) { (copy control and set location = mouse.X
and mouse.Y) }
OnMouseUp = Create new control on form at Mouse.X and Mouse.Y set
bMoving = false;

Nov 5 '07 #2
Trecius wrote:
Hello, Newsgroupians:

I've been looking on the Internet for some resources to create a simple
drag-and-drop application, but they all seem too complicated or not what I
need.
Here are some simple explanations:

http://tinyurl.com/yeb6am
http://tinyurl.com/2k7zo2

>
I have created a Form with a ToolStrip that has a couple of buttons at the
top. What I want to do is allow the user to drag one of the button's from
the toolstrip to the client area. Once the user let's go, I want to create a
button in the client area at that point. This mimics Visual Studio when
visually creating Forms. Does anyone have any short code or resources that
could allow me to do this?
Here's some sample code:

using System.Windows.Forms;
using System.Drawing;
using System;

namespace WindowsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

newToolStripButton.MouseDown += newToolStripButton_MouseDown;
newToolStripButton.MouseUp += newToolStripButton_MouseUp;
newToolStripButton.MouseMove += newToolStripButton_MouseMove;
newToolStripButton.MouseLeave += newToolStripButton_MouseLeave;

AllowDrop = true;// just for demo purposes :-)
}
void newToolStripButton_MouseLeave(object sender, EventArgs e)
{
isDragging = false;
}
void newToolStripButton_MouseMove(object sender, MouseEventArgs e)
{
if(!isDragging)
return;
Size dragSize = SystemInformation.DragSize;
int dx = Math.Abs(dragPoint.X - e.X);
int dy = Math.Abs(dragPoint.Y - e.Y);

if(dx < dragSize.Width || dy < dragSize.Height)
return;
IDataObject data = new DataObject();
data.SetData(newToolStripButton);// D&D data
DragDropEffects res = DoDragDrop(data, DragDropEffects.All
| DragDropEffects.Link);
}
void newToolStripButton_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
void newToolStripButton_MouseDown(object sender, MouseEventArgs e)
{
isDragging = true;
dragPoint = new Point(e.X, e.Y);
}
private bool isDragging = false;
private Point dragPoint = new Point();

protected override void OnDragOver(DragEventArgs drgevent)
{
if (drgevent.Data.GetDataPresent(typeof(ToolStripButt on)))
drgevent.Effect = DragDropEffects.Link;
}
protected override void OnDragDrop(DragEventArgs drgevent)
{
if (!drgevent.Data.GetDataPresent(typeof(ToolStripBut ton)))
return;
MessageBox.Show(((ToolStripButton)
drgevent.Data.GetData(typeof (ToolStripButton))).Text);
}
}
}
HTH,
Andy

--
You can email me by removing the NOSPAM parts below:
xm**********@gmxNOSPAM.net
Nov 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: hemant_mishal | last post by:
Hi All, I am writting a java script library which will provide inter frame drag and drop operation. The more precise will be OLE drag and drop, which means only data will be transfered from frame...
0
by: Lauren Quantrell | last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.) onto a field in Access2K and capture the full file path. I found an posting below that says this is possible but I cannot...
2
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
3
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
6
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
3
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
0
by: ViRi | last post by:
I am currently experimenting a bit with AxMicrosoft.MediaPlayer.Intero­p.AxWindowsMediaPlayer and so far, most has gone well. Currently, i would like to add drag-and-drop functionality to the...
1
by: Darren | last post by:
I'm trying to create a file using drag and drop. I want to be able to select a listview item drag it to the shell and create a file. Each icon in the listview represents a blob in a database. When...
0
by: RHSFSS | last post by:
Hi, I have a Drag and Drop registration problem (See http://www.thescripts.com/forum/thread434707.html for similar problem post), can anyone out thereadvise on the best solution? I have a .NET 2.0 ...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.