Click here to Skip to main content
15,904,416 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Outlook-style mini calendar Pin
Heath Stewart21-Oct-04 7:44
protectorHeath Stewart21-Oct-04 7:44 
GeneralRe: Outlook-style mini calendar Pin
machocr21-Oct-04 9:40
machocr21-Oct-04 9:40 
GeneralRe: Outlook-style mini calendar Pin
Jordi Corominas7-Nov-04 21:47
Jordi Corominas7-Nov-04 21:47 
Generalrun .net app in all systems Pin
visitsaadi21-Oct-04 4:50
visitsaadi21-Oct-04 4:50 
GeneralRe: run .net app in all systems Pin
J4amieC21-Oct-04 4:59
J4amieC21-Oct-04 4:59 
GeneralRe: run .net app in all systems Pin
McClamm21-Oct-04 5:29
McClamm21-Oct-04 5:29 
GeneralRe: run .net app in all systems Pin
Heath Stewart21-Oct-04 7:14
protectorHeath Stewart21-Oct-04 7:14 
GeneralRe: run .net app in all systems Pin
McClamm21-Oct-04 9:01
McClamm21-Oct-04 9:01 

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.