This project is read-only.

WinForms Drag and Drop

Topics: User Forum
Jul 14, 2010 at 1:03 PM
Edited Jul 15, 2010 at 12:32 PM

Hi,

 

How use "Drag and Drop" in windows forms? sorry, but i do not understand ...

 

obs: Not from explorer onto Scintilla.

 

is WinForm drag events onto Scintilla.

 

i try, but the drags events never is fired...

 

i read the topic: http://scintillanet.codeplex.com/Thread/View.aspx?ThreadId=73413

 

in this topic, say -> "drag/drop between ScintillaNET and the .NET RichTextBox"

 

there is an exemple??? or sample code??? how do that?

 


Jul 19, 2010 at 3:32 AM

I've also confirmed that the WinForms drag and drop events do not fire for ScintillaNet.  However, I do have a workaround.  It's possible to create an invisible Panel control over the Scintilla control, and use the Panel to catch the drag events.  Here's the basic idea:

1) Create a class that inherits from Panel, overrides CreateParams, and sets its style like this:

createParams.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT

2) Create an instance of the transparent panel, and call functions like these whenever the drag starts and ends:

public void StartDrag()
{
  if(m_draggingItem)
  {
    return;
  }

  m_draggingItem = true;
  m_dragInitialized = false;

  m_transPanel.Bounds = scintilla1.Bounds;
  m_transPanel.BringToFront();
}

public void EndDrag()
{
  m_draggingItem = false;
  m_transPanel.SendToBack();
}

3) Hook up the panel's drag events with functions like these:

private void transPanel_DragEnter(object sender, DragEventArgs de)
{
  if(m_draggingItem && m_dragInitialized)
  {
    return;
  }

  // do whatever setup stuff here

  m_dragInitialized = true;
}

private void transPanel_DragOver(object sender, DragEventArgs de)
{
  if(m_draggingItem)
  {
    // do stuff here if necessary
  }
}

private void transPanel_DragDrop(object sender, DragEventArgs de)
{
  if(m_draggingItem)
  {
    // handle drop here
  }
}

Hopefully that gives you enough of a feel for how I have it working.

Jul 19, 2010 at 12:44 PM

greate solution...

thanks!

 


i try other think.

 

private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
this.DoDragDrop( ( ( TreeNode )e.Item ).Text + , DragDropEffects.Copy );
}


but...

all controls on the form (this) are affected.

your solution seems more "safe".


thanks again...