[英]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表单事件时,它应该工作。
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.