我需要从事件中获取mouseDown事件的发送者,并将其设置为在dragDrop事件中使用的全局变量,以便根据拖动的图片框调用方法。我需要控件名称或其他东西。我的尝试:
全局变量“dragSource”:
public partial class MapDesignerView : Form
{
public Map myMap { get; set; }
public MapController myMapController { get; set; }
public MapConstructor myMapConstructor { get; set; }
public MouseEventHandler myDetectMouse { get; set; }
object dragSource = null;
鼠标按下
private void pbxMinotaur_MouseDown(object sender, MouseEventArgs e)
{
pbxMap.AllowDrop = true;
pbxMinotaur.DoDragDrop(pbxMinotaur.Name, DragDropEffects.Copy |
DragDropEffects.Move);
dragSource = sender;
}
的DragDrop
private void pbxMap_DragDrop(object sender, DragEventArgs e)
{
{
if (dragSource == pbxMinotaur)
{
myDetectMouse.setMinotaur(e, myMap.myCells);
}
答案 0 :(得分:1)
那究竟什么不起作用......我能想到的唯一可能导致问题的是你在拖动源中存储对整个控件的引用。
更好的想法可能只是故事Id。然后根据Id进一步测试它。
string dragSourceName = null;
private void pbxMinotaur_MouseDown(object sender, MouseEventArgs e)
{
pbxMap.AllowDrop = true;
pbxMinotaur.DoDragDrop(pbxMinotaur.Name, DragDropEffects.Copy |
DragDropEffects.Move);
Control c = (sender as Control);
if(c != null)
dragSourceName = c.Name;
}
private void pbxMap_DragDrop(object sender, DragEventArgs e)
{
if (dragSourceName == pbxMinotaur.Name)
{
myDetectMouse.setMinotaur(e, myMap.myCells);
}