Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Drag Drop
Message
De
01/09/2009 13:25:20
 
 
À
01/09/2009 11:36:33
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Divers
Thread ID:
01408295
Message ID:
01422180
Vues:
39
>Thanks Bonnie,
>That did it.


Cool! Lucky guess. <g>

~~Bonnie


>
>>Jim,
>>
>>I think maybe it should be this (just a guess though, because I don't know what this Bit class is):
>>
>>
>>                Bit newBit = (Bit)e.Data.GetData(typeof(Bit));
>>
>>
>>Will that work for you?
>>
>>~~Bonnie
>>
>>
>>
>>
>>
>>
>>>Thanks Bonnie,
>>>I'll try to explain my problem. I am starting a drag operation from a toolstripbutton on a form.
>>>
>>>       //This code is on a toolbar of the form
>>>        private void toolStripButton2_MouseDown(object sender, MouseEventArgs e)
>>>        {
>>>            Bit XIC = new Bit();
>>>            XIC.BitType = Enums.bitType.NormallyClosed;
>>>            DoDragDrop(XIC, DragDropEffects.Copy);
>>>        }
>>>
>>>
>>>The XIC.BitType is information I need in a switch statement.
>>>The target is a user control inside the form. When dropped I need the XIC.BitType in order to determine which graphic to display.
>>>
>>>
>>>       //This code is on the user controlthat is on the form
>>>        private void Rung_DragDrop(object sender, DragEventArgs e)
>>>        {
>>>            Rung targetRung = (Rung)sender;
>>>            if( e.Data.GetDataPresent(typeof(Bit)))
>>>            
>>>            {                
>>>                Bit newBit = new Bit();
>>>                newBit.BitType = (Enums.bitType)e.Data.GetData("BitType"); // this is where my code breaks or I should say never runs.
>>>                newBit.Location = targetRung._ConnectionPoint;
>>>                
>>>                this.Controls.Add(newBit);
>>>                Elements.Add(newBit);
>>>                this.VisualCueImage.Visible = false;
>>>                
>>>            }
>>>            
>>>        }
>>>
>>>
>>>While in debug, I can find the BitType in e.Data, but I have to drill down about eight levels.
>>>
>>>>>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
Répondre
Fil
Voir

Click here to load this message in the networking platform