【问题标题】:Windows.Forms DragLeave Event Firing unexpectedlyWindows.Forms DragLeave 事件意外触发
【发布时间】:2012-10-03 19:58:49
【问题描述】:

自定义 UserControl ChartControlShelf 包含一个带有 3 个子控件的 TableLayoutPanel,所有类型均为 Panel。孩子没有事件处理程序。

ShelfContainer 为 UserControl ChartControlShelf 添加所有 EventHandlers:

ChartControlShelf chartControlShelf = new ChartControlShelf();
chartControlShelf.DragOver+=new DragEventHandler(chartControlShelf_DragOver);
chartControlShelf.DragLeave+=new EventHandler(chartControlShelf_DragLeave); 

....

private void chartControlShelf_DragOver(object sender, DragEventArgs e) {

        ChartControlShelf chartControlShelf = (ChartControlShelf)sender;

        if (chartControlShelf.panelControlShelf.PointToClient(Cursor.Position).Y < chartControlShelf.tlpChartControlShelf.Size.Height / 2) {
            chartControlShelf.panelInsertTop.BackColor = CustomColorsColors.DragEnter;
            chartControlShelf.panelInsertBottom.BackColor = CustomColorsColors.DragLeave;
        }
        else {
            chartControlShelf.panelInsertBottom.BackColor = CustomColorsColors.DragEnter;
            chartControlShelf.panelInsertTop.BackColor = CustomColorsColors.DragLeave;
        }
   }

    private void chartControlShelf_DragLeave(object sender, EventArgs e) {
        ChartControlShelf chartControlShelf = (ChartControlShelf)sender;
        chartControlShelf.panelInsertTop.BackColor = CustomColorsColors.DragLeave;
        chartControlShelf.panelInsertBottom.BackColor = CustomColorsColors.DragLeave;

    }

为什么*chartControlShelf_DragLeave* 在我的鼠标离开ChartControlShelf UserControl之前触发?

【问题讨论】:

    标签: c# winforms events event-handling drag-and-drop


    【解决方案1】:

    鼠标光标“属于”指针下方直接可见的控件。听起来很奇怪,当光标“进入”ChartControlShelf 中的某个控件时,它也“离开”了 ChartControlSelf。

    【讨论】:

    • 我遇到了类似的问题,您的回答为我指明了正确的方向。我的解决方案是在所有控件上将属性 AllowDrop 设置为 false,除了主控件。
    猜你喜欢
    • 1970-01-01
    • 2011-02-07
    • 2015-05-03
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    相关资源
    最近更新 更多