Recently I got some email about how some of the VB.Net code I posted on the drag/drop series should translate to C#, specifically about these fragments.
If (e.AllowedEffects And DragDropEffects.Copy) = 0 AndAlso _
(e.AllowedEffects And DragDropEffects.Move) = 0 Then
e.Effects = DragDropEffects.None
' Figure out whether we should copy or move. If we can do either, we'll move unless
' Ctrl is pressed.
If (e.AllowedEffects And DragDropEffects.Copy) <> 0 AndAlso _
(e.AllowedEffects And DragDropEffects.Move) <> 0 Then
If (e.KeyStates And DragDropKeyStates.ControlKey) <> 0 Then
e.Effects = DragDropEffects.Copy
And is the bitwise & operator. Read this for more information.
In the first snippet, typically AllowedEffects will be one or more of Copy, Move and Link (DragDropEffect values are used as flags). I only handle Copy and Move, so if neither of them is set, I bail out in the first check.
In the second snippet, if I can Copy and Move the item, I’ll have to pick one. I decided to go with Move by default, and allow the user to toggle this behavior by using the control key.
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm.