Click here to Skip to main content
15,920,828 members
Home / Discussions / C#
   

C#

 
GeneralRe: Interface confusion Pin
Nick Parker21-Oct-04 10:58
protectorNick Parker21-Oct-04 10:58 
GeneralRe: Interface confusion Pin
Christian Graus21-Oct-04 11:12
protectorChristian Graus21-Oct-04 11:12 
GeneralRe: Interface confusion Pin
Adam °Wimsatt21-Oct-04 12:01
Adam °Wimsatt21-Oct-04 12:01 
GeneralRe: Interface confusion Pin
Christian Graus21-Oct-04 12:17
protectorChristian Graus21-Oct-04 12:17 
GeneralRe: Interface confusion Pin
Nick Parker21-Oct-04 10:53
protectorNick Parker21-Oct-04 10:53 
Generalwsock32.dll Pin
Anonymous21-Oct-04 9:40
Anonymous21-Oct-04 9:40 
GeneralInterfacing with a Web Service Pin
Member 53435721-Oct-04 8:34
Member 53435721-Oct-04 8:34 
GeneralRe: Interfacing with a Web Service Pin
Salil Khedkar25-Oct-04 1:06
Salil Khedkar25-Oct-04 1:06 
QuestionHow to allow user to select an ROI Pin
Kiran Satish21-Oct-04 8:17
Kiran Satish21-Oct-04 8:17 
GeneralWindows Service name/description Pin
petst21-Oct-04 6:49
petst21-Oct-04 6:49 
GeneralRe: Windows Service name/description Pin
Heath Stewart21-Oct-04 6:57
protectorHeath Stewart21-Oct-04 6:57 
GeneralRe: Windows Service name/description Pin
petst21-Oct-04 9:18
petst21-Oct-04 9:18 
GeneralwParam, lParam Help Pin
Keith La Force21-Oct-04 6:23
Keith La Force21-Oct-04 6:23 
GeneralRe: wParam, lParam Help Pin
Heath Stewart21-Oct-04 6:50
protectorHeath Stewart21-Oct-04 6:50 
GeneralDrag-and-drop Panel control Pin
zsiga21-Oct-04 6:02
zsiga21-Oct-04 6:02 
GeneralRe: Drag-and-drop Panel control Pin
Heath Stewart21-Oct-04 7:07
protectorHeath Stewart21-Oct-04 7:07 
What does the control's ID have to do with anything? Drag-n-drop in .NET is simple. Just read the documentation for the Control.DragDrop[^] event for information and a complete example.

Dragging the Panel is the slightly more difficult part, since it doesn't define an event to fire when dragging begins (nor would it makes sense to in most circumstances). Instead, you'll need to handle MouseDown, MouseMove, and MouseUp as we've discussed before in this forum:
bool down;
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
  down = true;
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
  if (down)
  {
    DataObject data = new DataObject(sender.GetType().FullName, sender);
    DoDragDrop(data, DragDropEffects.Move);
 
    down = false; // Don't want to keep doing this
  }
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
  down = false;
}
Of course, you'll need to add these handlers to the Panel corresponsing events.

The code for the DragOver and DragDrop events you can find in the documentation I linked above.

Note that this will only work within the same AppDomain. You can't simply drag instances from one AppDomain to another. For that you need to serialize the panel and pack it in a DataObject as a string, or study OLE Drag and Drop (from which .NET drag and drop derives) and structure storage and stream information. Serializing the object to a string is the easiest alternative since .NET drag and drop doesn't expose other possible STDMEDIUMs with which to store object data (like locking it into global memory so you can use Marshal.AllocHGlobal, for example).

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: Drag-and-drop Panel control Pin
zsiga22-Oct-04 3:33
zsiga22-Oct-04 3:33 
GeneralRe: Drag-and-drop Panel control Pin
Heath Stewart22-Oct-04 8:30
protectorHeath Stewart22-Oct-04 8:30 
GeneralRe: Drag-and-drop Panel control Pin
zsiga23-Oct-04 2:51
zsiga23-Oct-04 2:51 
GeneralRe: Drag-and-drop Panel control Pin
Heath Stewart23-Oct-04 5:32
protectorHeath Stewart23-Oct-04 5:32 
GeneralRe: Drag-and-drop Panel control Pin
zsiga24-Oct-04 0:43
zsiga24-Oct-04 0:43 
GeneralRe: Drag-and-drop Panel control Pin
Heath Stewart24-Oct-04 4:40
protectorHeath Stewart24-Oct-04 4:40 
GeneralOutlook-style mini calendar Pin
machocr21-Oct-04 4:57
machocr21-Oct-04 4:57 
GeneralRe: Outlook-style mini calendar Pin
Heath Stewart21-Oct-04 7:07
protectorHeath Stewart21-Oct-04 7:07 
GeneralRe: Outlook-style mini calendar Pin
machocr21-Oct-04 7:15
machocr21-Oct-04 7:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.