2
自定義UserControl ChartControlShelf
包含TableLayoutPanel
帶有3個子控件,所有類型Panel
。兒童沒有EventHandlers。Windows.Forms DragLeave事件意外觸發
ShelfContainer
將所有事件處理器的用戶控件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
用戶控件以前?
我有一個類似的問題,你的回答指出我在正確的方向。對我來說,解決方案是在除了主控件之外的所有控件上將屬性AllowDrop設置爲false。 –