How do I set up a dragover / dragdrop event handler in the MDI client area?

Using C # and .Net framework 2.0. I have an MDI application and need to handle dragover / dragdrop events. I have a list attached to the left of my application and you want it to be able to drag an item from the list and drop it in the MDI client area and have the correct MDI file to open the item. I can't figure out where to attach the handler. I tried to connect to the main events of the form and MdiClient that are part of the form, but none of the event handlers seem to be called when I expect them.

I am also using Infragistics Tabbed MDI Manager, so I am not sure if this affected it.

0


source to share


2 answers


I have an application that implements the Infragistics MDI DockManager (not the Tabbed MDI), but I think they are very similar. It should work when you handle MDI form events.

  • Is MDIForm.AllowDrop true?
  • The object you are trying to drag and drop serializable?
  • Try DragEnter event instead of DragOver


As a last resort: if all else fails, try contacting Infragistics support.

+2


source


This code worked for me. It opens a new MDI file when dropping text in the parent MDI form.



...
using System.Linq;
...

public partial class Form1 : Form
{
    MdiClient mdi_client;
    public Form1()
    {
        InitializeComponent();
        mdi_client = this.Controls.OfType<MdiClient>().FirstOrDefault();
        mdi_client.AllowDrop = true;
        mdi_client.DragEnter += Form1_DragEnter;
        mdi_client.DragDrop += Form1_DragDrop;
    }

    private void Form1_DragDrop(object sender, DragEventArgs e)
    {
        myForm m = new myForm();
        m.Text = (string)e.Data.GetData(typeof(string));
        m.MdiParent = this;
        m.Show();
        m.Location = mdi_client.PointToClient(new Point(e.X, e.Y));
    }

    private void Form1_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.All;
    }
}

      

0


source







All Articles