自定义UserControl ChartControlShelf
包含一个TableLayoutPanel
,其中包含3个子控件,所有类型都为Panel
。孩子们没有EventHandlers。
ShelfContainer
为UserControl添加所有EventHandler 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 *在鼠标离开ChartControlShelf
UserControl之前触发?
答案 0 :(得分:4)
鼠标光标“属于”指针下方直接可见的控件。听起来很奇怪,当光标“进入”ChartControlShelf中的一个控件时,它也“离开”ChartControlSelf。