Windows.Forms DragLeave 事件意外触发



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

ShelfContainer 为 UserControl ChartControlShelf 添加所有事件处理程序:

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用户控件之前触发 *chartControlShelf_DragLeave*?

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

相关内容

  • 没有找到相关文章

最新更新