简体   繁体   English

您如何在MDI客户区域中为拖动/拖放事件设置处理程序?

[英]How do you setup a handler for the dragover/dragdrop events in the MDI client area?

Using C# and the .Net framework 2.0. 使用C#和.Net Framework 2.0。 I have an MDI application and need to handle dragover/dragdrop events. 我有一个MDI应用程序,需要处理拖动/拖放事件。 I have a list docked to the left on my application and would like to be able to drag an item from the list and drop it in the MDI client area and have the correct MDI child for the item open. 我有一个停靠在应用程序左侧的列表,希望能够从列表中拖动一个项目并将其放在MDI客户区中,并为该项目打开正确的MDI子项。 I can't seem to figure out where to attach the handler. 我似乎无法弄清楚附加处理程序的位置。 I've tried attaching to the main form's events and the MdiClient that is part of the form, but neither event handler seems to get called when I expect them to. 我尝试附加到主窗体的事件和作为窗体一部分的MdiClient,但是在我希望它们出现时似乎都未调用任何事件处理程序。

I'm also using an Infragistics Tabbed MDI Manager, so I'm not sure if that's affecting it. 我还使用了Infragistics选项卡式MDI管理器,因此不确定是否会影响它。

I have an application that implements the Infragistics MDI DockManager (not Tabbed MDI), but I think those are very similar. 我有一个实现Infragistics MDI DockManager(不是选项卡式MDI)的应用程序,但我认为它们非常相似。 It should work when you handle the MDI form events. 当您处理MDI表单事件时,它应该工作。

  • MDIForm.AllowDrop is set to true? MDIForm.AllowDrop是否设置为true?
  • Is the object you're trying to drag serializable? 您要拖动的对象是否可序列化?
  • Try the DragEnter event instead of DragOver 尝试使用DragEnter事件而不是DragOver

As a last resort: if everything else fails, try contacting Infragistics Support. 作为最后的选择:如果其他所有操作失败,请尝试与Infragistics支持联系。

This code worked for me. 这段代码对我有用。 It opens a new MDI child on dropping some text on MDI parent form. 当在MDI父窗体上放置一些文本时,它将打开一个新的MDI子窗体。

...
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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TreeView会触发DragEnter,DragOver和DragLeave事件,但不会触发DragDrop - TreeView fires DragEnter, DragOver and DragLeave events, but won't fire DragDrop DragDrop 功能如何在 WPF 中工作? 深入了解 DragDrop 及相关事件 - How DragDrop features work in WPF? Deep understanding of DragDrop and related events 你如何设置 MvxSuspensionManager - How do you setup MvxSuspensionManager 我的 MDI 客户端区域的真实大小 - 高度 - 14? - True size of my MDI Client area - height - 14? 如何将上面带有tab控件的MDI子窗体加载到您从MDI父菜单栏中选择的特定选项卡上 - How do you load a MDI child form that has a tabcontrol on it to a specific tab of your choosing from a MDI parent menustrip 为什么事件“ gridControl1_DragDrop”和“ gridControl1_DragOver”不起作用 - Why the event “gridControl1_DragDrop” and “gridControl1_DragOver” does not work 如何在MDI中启动鼠标事件? - How can I initiate mouse events in MDI? 如何为安装项目创建属性? - How do you Create Properties For Setup Project? 您如何以编程方式设置 GLWpfControl? - How do you programmatically setup the GLWpfControl? C# - 如何为MdiChildren设置一个小的Mdi“区域”? - C# - How to set up a small Mdi “area” for MdiChildren?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM