Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Drag Drop
Message
De
30/06/2009 02:02:47
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Divers
Thread ID:
01408295
Message ID:
01409283
Vues:
50
>Do you have any code to demonstrate this?

Here's a little blurb I wrote up awhile back:

Drag / Drop for Controls that do not have an ItemDrag event:
private Control PickedUpControl;
private Panel   TargetArea;

this.TargetArea.AllowDrop = true;

private void DragControl_MouseDown(object sender, System.MouseEventArgs e)
{
	this.PickedUpControl = (Control)sender;
	this.PickedUpControl.DoDragDrop(sender, DragDropEffects.Move);
}
private void TargetArea_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
	e.Effect = DragDropEffects.All;
}
private void TargetArea_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
	this.TargetArea.Controls.Add(this.PickedUpControl);
	Point xy = this.TargetArea.PointToClient(new Point(e.X, e.Y));
	this.PickedUpControl.Location = xy;
}

// The DragOver event is often redundant, but can be used to show the object moving
private void TargetArea_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
{
	e.Effect = DragDropEffects.All;
	Point xy = this.PointToClient(new Point(e.X+1, e.Y+1));
	this.PickedUpControl.Location = xy;
}
Another useful method if you need to actually *get* the object at that point in the DragDrop method is the .GetChildAtPoint() method (this would be *where* the Dragged-in control is being dropped, like say you were dropping the actual Text from one TextBox to another):
private void TargetArea_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
{
	Point pt = this.TargetArea.PointToClient(new Point(e.X, e.Y));
	Control ToControl = this.TargetArea.GetChildAtPoint(pt);
	
	ToControl.Text = this.PickedUpControl.Text;
}
~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform