自定义 UserControlChartControlShelf包含一个TableLayoutPanel带有 3 个子控件的所有类型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_DragLeave*在我的鼠标离开ChartControlShelfUserControl 之前触发?