Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Drag and Drop Control and Properties
Message
From
23/06/2010 20:36:28
 
 
To
22/06/2010 20:18:48
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01470266
Message ID:
01470369
Views:
45
Bill,

I've accomplished in the past by using the following code (hopefully it's complete, I'm taking bits and pieces from a sample app I use for testing stuff):

First, I define a PickedUpControl variable, and set it in a MouseDown event handler:
private System.Windows.Control PickedUpControl;

// You could use this same event handler for anything you want to move, not just this button
private void Button_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
	this.PickedUpControl = (Control)sender;
	this.PickedUpControl.DoDragDrop(sender, DragDropEffects.Move);
}
Let's also assume the Panel is called TargetArea, and you'd have the following code in the DragOver and DragDrop handlers:
private void TargetArea_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
	e.Effect = DragDropEffects.Move;
	Point xy = this.PointToClient(new Point(e.X+1, e.Y+1));
	this.PickedUpControl.Location = xy;
}
private void TargetArea_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
	Point xy = this.TargetArea.PointToClient(new Point(e.X, e.Y));
	this.TargetArea.Controls.Add(this.PickedUpControl);
	this.PickedUpControl.Location = xy;
}
The only thing this doesn't do is show the button once the the mouse has entered the target area ... you still see the little drag-effect box, but the button itself doesn't show up until you drop it. I never played around with it enough to figure out how to show it moving around inside the TargetArea, but it may be do-able. In any case, this code *does* move the button into the Panel (assuming I didn't leave out any important bits from my sample app).

~~Bonnie


>I'm doing application that requires me to move a button to a panel using drag and drop.
>I can move the button OK, but the text stays behind. When I move the text, the button stays behind.
>Ditto with the picture.
>I can't see how to make everything move over.
>Any ideas?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform