A custom UserControl ChartControlShelf contains a TableLayoutPanel with 3 child controls, all type Panel. Children have no EventHandlers.
ShelfContainer adds all EventHandlers for 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;
}
Why is the *chartControlShelf_DragLeave* firing before my mouse leaves the ChartControlShelf UserControl?
The mouse cursor “belongs” to the control directly visible below the pointer. As strange as it sounds, When the cursor “enters” one of the controls inside ChartControlShelf, it also “leaves” the ChartControlSelf.